0
0
SASSmarkup~8 mins

Why extending reduces duplication in SASS - Performance Evidence

Choose your learning style9 modes available
Performance: Why extending reduces duplication
MEDIUM IMPACT
This affects CSS file size and browser rendering speed by reducing repeated styles and selectors.
Applying the same styles to multiple selectors without repeating code
SASS
.button { color: blue; padding: 1rem; border-radius: 0.5rem; }
.card-button { @extend .button; }
Extending shares the same CSS rules, avoiding duplication and reducing file size.
📈 Performance GainSaves kilobytes in CSS size, improving LCP by reducing CSS download and parse time.
Applying the same styles to multiple selectors without repeating code
SASS
.button { color: blue; padding: 1rem; border-radius: 0.5rem; }
.card-button { color: blue; padding: 1rem; border-radius: 0.5rem; }
Repeating the same styles for multiple selectors increases CSS file size and parsing time.
📉 Performance CostAdds extra kilobytes to CSS bundle, increasing LCP by 50-100ms on slow networks.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Repeated styles without @extendNo extra DOM nodesNo extra reflowsHigher paint cost due to larger CSS[X] Bad
Using @extend to share stylesNo extra DOM nodesNo extra reflowsLower paint cost due to smaller CSS[OK] Good
Rendering Pipeline
When Sass @extend is used, the compiler merges selectors sharing styles, producing smaller CSS. This reduces the amount of CSS the browser must download and parse, speeding up style calculation and layout.
Style Calculation
Layout
Paint
⚠️ BottleneckStyle Calculation due to large CSS files with duplicated rules
Core Web Vital Affected
LCP
This affects CSS file size and browser rendering speed by reducing repeated styles and selectors.
Optimization Tips
1Use @extend to share styles and avoid repeating CSS rules.
2Smaller CSS files load and parse faster, improving page load speed.
3Reducing CSS duplication helps improve Largest Contentful Paint (LCP).
Performance Quiz - 3 Questions
Test your performance knowledge
How does using @extend in Sass affect CSS file size?
AIt reduces file size by merging duplicate styles
BIt increases file size by adding more selectors
CIt has no effect on file size
DIt duplicates styles in the CSS output
DevTools: Network
How to check: Open DevTools, go to Network tab, filter by CSS files, and compare file sizes before and after using @extend.
What to look for: Look for reduced CSS file size and faster CSS download times indicating less duplication.