Last active
April 20, 2022 16:00
-
-
Save gigo6000/9743475d1eb13794af0a17830b2f8a5a to your computer and use it in GitHub Desktop.
Critical CSS example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const critical = require("critical"); | |
const baseUrl = "https://www.github.com"; | |
const targetPath = "public/css/"; | |
const dimensions = [ | |
{ | |
width: 320, | |
height: 568, | |
}, | |
{ | |
width: 768, | |
height: 1024, | |
}, | |
{ | |
width: 1200, | |
height: 900, | |
}, | |
{ | |
width: 1920, | |
height: 3840, | |
}, | |
{ | |
width: 3840, | |
height: 3840, | |
}, | |
]; | |
const penthouse = { | |
timeout: 60000, | |
}; | |
console.log("Generating critical css..."); | |
process.setMaxListeners(100); | |
console.log("Generating " + "home_critical.min.css"); | |
critical.generate( | |
{ | |
src: baseUrl + "/", | |
target: targetPath + "home_critical.min.css", | |
dimensions, | |
inline: false, | |
penthouse, | |
}, | |
(err, { css, html, uncritical }) => { | |
if (err) { | |
console.log("err: ", err); | |
} | |
// console.log("css: ", css); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment