
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
critical-css
Advanced tools
Detects Above the Fold styles on sites and assembles a stylesheet of them.
Detects Above the Fold styles on sites and assembles a stylesheet of them.
Opens any web page on an accessible URL and runs a parser to detect above the fold CSS in the headless browser.
The module opens the supplied URL and runs a parser script which returns the stylesheet consisting critical style rules. This can be further processed in a callback function.
Operation is not limited to checking a single stylesheet as the parser script is injected to and runs in phantomjs.
The Grunt plugin grunt-critical-css uses this module.
Install the module via npm: npm install critical-css
var criticalCss = require('critical-css');
var options = {
width: 1050,
height: 800,
enabledOrigins: ['www.example.com']
}
criticalCss.generate('http://www.example.com/', function(err, output) {
if (err) {
throw new Error(err);
}
// Print the styles to the console.
console.log(output);
});
.generate(url, [options, callback])
The URL of the site to process. Must be accessible by phantom.
An optional object of options.
Type: Integer Default value: 1200
The width of the viewport used in the browser. Used to determine what is "above the fold", i.e what is visible during rendering the page initially.
Type: Integer Default value: 900
The height of the viewport used in the browser. Used to determine what is "above the fold", i.e what is visible during rendering the page initially.
Type: Array Default value: []
An array of CSS selectors or basically any pattern. These are matched against every individual style declaration and if the patterns provided here match the style rule is discarded from the output.
This can be useful to exclude certain 3rd party elements or any styles that are loaded asynchronously anyways.
options = {
excludeSelectors: [
'.dfp-tag-wrapper', // Asynchronous DFP ad formatting
'html, body, div' // CSS resets starting with "html, body, div"
]
};
Type: Array Default value: []
An array of host names to serve as a whitelist where CSS can originate from. Any
CSSRuleList objects with parentStyleSheet.href not having this host name are
excluded from the critical CSS.
This can be useful to exclude certain styles supplied by 3rd party widgets that are loaded asynchronously anyways.
options = {
enabledOrigins: ['cdn-1.example.com', 'cdn-2.example.com']
};
Type: Boolean Default value: false
Controls whether non-external styles should be included. These are usually rules which are already inlined or are set by JavaScript. These are excluded by default.
Type: Boolean Default value: true
Controls console output from the headless browser should be added to the output. Useful for debugging purposes.
Type: Integer Default value: 819200
Sets the output buffer for the child process.
Type: Function Default value:
function(err, output) {
if (err) {
throw new Error(err);
}
console.log(output);
};
An optional callback function with output being the value of stdout from the
child process (i.e the headless browser).
This project is under active development. New features, more tests and examples are in the works now.
Please head over to the issue queue to add suggestions or file bug reports.
Copyright (c) 2015 Attila Beregszaszi Licensed under the MIT license.
Development was sponsored by Front Seed Labs and Dennis Publishing
FAQs
Detects Above the Fold styles on sites and assembles a stylesheet of them.
The npm package critical-css receives a total of 12 weekly downloads. As such, critical-css popularity was classified as not popular.
We found that critical-css demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.