0
0
SASSmarkup~8 mins

Chained extensions in SASS - Performance & Optimization

Choose your learning style9 modes available
Performance: Chained extensions
MEDIUM IMPACT
Chained extensions affect CSS compilation time and the final CSS size, impacting page load speed and rendering performance.
Reusing styles with Sass @extend in a chain
SASS
%base-style { font-size: 1rem; margin: 1rem; padding: 1rem; }
.button { @extend %base-style; background: blue; color: black; }
Using a single @extend avoids deep selector chains and reduces duplicated styles, resulting in smaller CSS and faster rendering.
📈 Performance GainReduces CSS size by 20-30%, lowers style recalculations, and improves LCP by up to 100ms.
Reusing styles with Sass @extend in a chain
SASS
@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; }
Chaining multiple @extend selectors creates complex CSS selectors and duplicates styles, increasing CSS size and slowing down browser rendering.
📉 Performance CostIncreases CSS file size by 20-30%, triggers more style recalculations, and delays LCP by 50-100ms on average.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Long chained @extend selectorsNo direct DOM changesTriggers multiple style recalculationsHigher paint cost due to complex styles[X] Bad
Single-level @extend with consolidated stylesNo direct DOM changesMinimal style recalculationsLower paint cost with simpler styles[OK] Good
Rendering Pipeline
Chained Sass extensions increase the complexity of generated CSS selectors, which the browser must parse and apply during Style Calculation and Layout stages.
Style Calculation
Layout
Paint
⚠️ BottleneckStyle Calculation due to complex and duplicated selectors
Core Web Vital Affected
LCP
Chained extensions affect CSS compilation time and the final CSS size, impacting page load speed and rendering performance.
Optimization Tips
1Avoid deep chains of Sass @extend to keep CSS simple.
2Consolidate shared styles into single placeholders to reduce duplication.
3Smaller, simpler CSS improves browser style calculation and page load speed.
Performance Quiz - 3 Questions
Test your performance knowledge
What is a main performance drawback of using chained Sass @extend selectors?
AThey cause more JavaScript to run on the page.
BThey reduce the number of CSS selectors, improving performance.
CThey increase CSS file size and complexity, slowing style calculation.
DThey prevent the browser from caching CSS files.
DevTools: Performance
How to check: Record a performance profile while loading the page, then inspect the 'Style Recalculation' and 'Layout' events to see if complex selectors cause delays.
What to look for: Look for long style recalculation times and large CSS files in the Network panel indicating chained extensions impact.