Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

inline-critical

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inline-critical - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

test/expected/external-ignore-expected.html

19

index.js

@@ -56,6 +56,21 @@ /**

var links = $('link[rel="stylesheet"]');
var links = $('link[rel="stylesheet"]').filter(function(){
return !$(this).parents('noscript').length;
});
var noscript = $('<noscript>\n</noscript>');
var o = options || {};
if (_.isString(o.ignore)) {
o.ignore = [o.ignore];
}
if (o.ignore) {
links = links.filter(function() {
var href = $(this).attr('href');
return _.findIndex(o.ignore, function(arg) {
return _.isRegExp(arg) && arg.test(href) || arg === href;
}) === -1;
});
}
// minify if minify option is set

@@ -75,2 +90,4 @@ if (o.minify) {

// extract styles from stylesheets if extract option is set

@@ -77,0 +94,0 @@ if (o.extract) {

2

package.json
{
"name": "inline-critical",
"version": "0.1.4",
"version": "0.2.0",
"description": "Inline critical-path css and load the existing stylesheets asynchronously",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -26,4 +26,16 @@ # inline-critical

## `inline(html, styles, options?)
## Example Usage ignoring stylesheet per regex
``` js
var inline = require('inline-critical');
var html = fs.readFileSync('test/fixtures/index.html', 'utf8');
var critical = fs.readFileSync('test/fixtures/critical.css', 'utf8');
var inlined = inline(html, critical, {
ignore: [/bootstrap/]
});
## inline(html, styles, options?)
- `html` is the HTML you want to use to inline your critical styles, or any other styles

@@ -35,2 +47,3 @@ - `styles` are the styles you're looking to inline

- `basePath` will be used when extracting styles to find the files references by `href` attributes
- `ignore` ignore matching stylesheets when inlining.

@@ -37,0 +50,0 @@ ## License

@@ -106,2 +106,42 @@ 'use strict';

});
it('should respect ignore option with string', function(done) {
function strip2(string) {
return string.replace(/\s+/gm,'');
}
var html = read('test/fixtures/external.html');
var expected = read('test/expected/external-ignore-expected.html');
var css = read('test/fixtures/critical.css');
var out = inlineCritical(html, css, {ignore: ['bower_components/bootstrap/dist/css/bootstrap.css']});
expect(strip2(out.toString('utf-8'))).to.be.equal(strip2(expected));
done();
});
it('should respect ignore option with RegExp', function(done) {
function strip2(string) {
return string.replace(/\s+/gm,'');
}
var html = read('test/fixtures/external.html');
var expected = read('test/expected/external-ignore-expected.html');
var css = read('test/fixtures/critical.css');
var out = inlineCritical(html, css, {ignore: [/bootstrap/]});
expect(strip2(out.toString('utf-8'))).to.be.equal(strip2(expected));
done();
});
it('should ignore stylesheets wrapped in noscript', function(done) {
var html = read('test/fixtures/index-noscript.html');
var css = read('test/fixtures/critical.css');
var expected = read('test/expected/index-noscript-inlined-minified-final.html');
var out = inlineCritical(html, css, { minify: true });
expect(strip(out.toString('utf-8'))).to.be.equal(strip(expected));
done();
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc