![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
critical-css-parser
Advanced tools
Get critical (above-the-fold) and the rest CSS using Puppeteer.
Critical-css-parser allows you to receive critical (above-the-fold) and the rest CSS. It might be helpful to speed up initial rendering of a web page. More information.
There are 3 types of input information: HTML and CSS, URL and localServer.
Critical-css-parser uses Puppeteer and DropCSS under the hood, so IT ALSO SUPPORTS ADAPTIVE DESIGN (BOTH DESKTOP AND MOBILE VERSIONS)! It also supports minifying (by CSSO).
This library is part of other projects: critical-css-inliner, webpack-critical-css-inliner
npm install --save-dev critical-css-parser
// or
yarn add --dev critical-css-parser
const criticalCSSParser = require('critical-css-parser');
(async () => {
const result = await criticalCSSParser({
type: 'URL',
URL: 'https://abvcss.github.io/abvcss-website/', // try to check your site
enableGoogleFonts: false,
whitelist: /#foo|\.bar/
});
console.log(result.critical); // ''
console.log(result.rest); // ':not(pre)>code[class*=language-]{background:#272822}:not(pre)>code[class*=language-]{'
})();
const criticalCSSParser = require('critical-css-parser');
(async () => {
const result = await criticalCSSParser({
type: 'localServer',
entrypoint: './www',
filename: 'index.html',
enableGoogleFonts: true
});
console.log(result.critical); // 'html{font-size: 10pt;}div{color: red;}'
console.log(result.rest); // 'p{color: red;}'
})();
const criticalCSSParser = require('critical-css-parser');
const html = `
<html>
<head></head>
<body>
<p>Hello <a href="#">World!</a></p>
</body>
</html>
`;
const css = `
.card {
padding: 8px;
}
p:hover a:first-child {
color: red;
}
`;
(async () => {
const result = await criticalCSSParser({
type: 'HTML',
html,
css,
minify: true // good way to optimize size
});
console.log(result.critical); // 'p:hover a:first-child{color:red}'
console.log(result.rest); // '.card{padding:8px}'
})();
Pass options to criticalCSSParser({ ... })
.
Parameters
options
Properties
type
String One of: HTML, URL or localServer. REQUIRED
html
String Your custom html code (default: '') REQUIRED FOR type === HTML
css
String Your custom css code (default: '') REQUIRED FOR type === HTML
URL
String URL of the page you need to optimize (default: '') REQUIRED FOR type === URL
entrypoint
String Root of your application (default: '') REQUIRED FOR type === localServer
filename
String Your index file (default: 'index.html')
enableGoogleFonts
Boolean Set true to except Google Font styles (default: false
)
whitelist
RegExp Whitelist of the critical CSS (default: /#fooBazBarAboveTheFold8917/
)
minify
Boolean Set true to minify resulting styles (default: false
)
<Promise<{ critical, rest }>>
critical - above-the-fold CSS. These styles you can put into your <style>
tag.
rest - other CSS. You can lazy-load the rest like this.
MIT license
FAQs
Get critical (above-the-fold) and the rest CSS using Puppeteer.
The npm package critical-css-parser receives a total of 1 weekly downloads. As such, critical-css-parser popularity was classified as not popular.
We found that critical-css-parser 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.