Performance: Extend limitations and gotchas
MEDIUM IMPACT
Using @extend in Sass affects CSS generation size and browser rendering performance by increasing selector complexity and causing style recalculations.
@mixin button-styles { padding: 1rem; background: blue; } .button { @include button-styles; } .card { @include button-styles; color: white; }
.button { padding: 1rem; background: blue; } .card { @extend .button; color: white; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| @extend with many selectors | No extra DOM nodes | Triggers multiple reflows if styles change | High paint cost due to complex styles | [X] Bad |
| Mixin for style reuse | No extra DOM nodes | Single reflow on style change | Lower paint cost with simpler styles | [OK] Good |