Performance: Critical CSS extraction strategies
This concept affects the page's initial load speed by optimizing how CSS is delivered and rendered for above-the-fold content.
Jump into concepts and practice - no test required
/* Extract critical CSS manually or via tool */ <style> /* Inline only critical CSS here */ </style> <link rel="stylesheet" href="styles.css" media="print" onload="this.media='all'"> <noscript><link rel="stylesheet" href="styles.css"></noscript>
@import 'full-styles.scss'; /* All styles loaded in one big CSS file */
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full CSS loaded upfront | Minimal DOM impact | Triggers 1 reflow after full CSS load | High paint cost due to blocking | [X] Bad |
| Critical CSS inlined + async load | Minimal DOM impact | Single reflow after critical CSS paint | Lower paint cost, faster visible content | [OK] Good |
Critical CSS extraction in web development?@mixin critical-button {
background-color: blue;
color: white;
padding: 1rem;
}
.critical {
@include critical-button;
font-weight: bold;
}What CSS will be generated for the .critical class?@include critical-button inserts all styles from the mixin into .critical..critical class gets background-color, color, padding from mixin plus font-weight: bold.@mixin critical-text {
font-size 1.2rem;
color: black;
}
.text {
@include critical-text;
}font-size 1.2rem; is missing a colon between property and value.