Performance: Chained extensions
Chained extensions affect CSS compilation time and the final CSS size, impacting page load speed and rendering performance.
%base-style { font-size: 1rem; margin: 1rem; padding: 1rem; }
.button { @extend %base-style; background: blue; color: black; }@mixin base { color: black; } %base-style { font-size: 1rem; } %extended-style { @extend %base-style; margin: 1rem; } %final-style { @extend %extended-style; padding: 1rem; } .button { @extend %final-style; background: blue; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Long chained @extend selectors | No direct DOM changes | Triggers multiple style recalculations | Higher paint cost due to complex styles | [X] Bad |
| Single-level @extend with consolidated styles | No direct DOM changes | Minimal style recalculations | Lower paint cost with simpler styles | [OK] Good |
@extend in Sass allow you to do?@extend basics@extend lets one selector reuse styles from another selector or placeholder.@extend = inherit styles step-by-step [OK]@extend with creating new CSS properties@extend compiles to JavaScript@extend adds inline HTML styles@extend syntax@extend keyword with a percent sign for placeholders and dot for classes.@extend.@extend syntax uses @extend keyword and proper selector symbols [OK]%base { color: blue; }
.button {@extend %base; font-weight: bold;}
.primary {@extend .button; background: yellow; }.primary?@extend chaincolor: blue;. .primary extends .button, so it inherits both color: blue; and font-weight: bold;.background: yellow; to inherited styles, so final CSS includes all three properties.%base { color: red; }
.button { @extend %base }
.primary { @extend .button; }@extend syntax@extend statement must end with a semicolon. The line @extend %base is missing it.@extend %base -> Option D@extend with semicolon [OK].primary and .secondary. Using chained extensions, which Sass code correctly shares the base styles and adds variant colors?Pass the test and this pattern moves unknown