Skip to content

Instantly share code, notes, and snippets.

@gigo6000
Last active April 20, 2022 16:00
Show Gist options
  • Save gigo6000/9743475d1eb13794af0a17830b2f8a5a to your computer and use it in GitHub Desktop.
Save gigo6000/9743475d1eb13794af0a17830b2f8a5a to your computer and use it in GitHub Desktop.
Critical CSS example
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