Performance: Maps for grouped values
MEDIUM IMPACT
Using maps for grouped values affects CSS generation size and style recalculation speed in the browser.
$theme: ( colors: ( primary: #0055ff, secondary: #ffaa00 ), font-sizes: ( small: 0.8rem, large: 1.5rem ) ); .button-primary { color: map-get(map-get($theme, colors), primary); font-size: map-get(map-get($theme, font-sizes), large); } .button-secondary { color: map-get(map-get($theme, colors), secondary); font-size: map-get(map-get($theme, font-sizes), small); }
$primary-color: #0055ff; $secondary-color: #ffaa00; $font-size-small: 0.8rem; $font-size-large: 1.5rem; .button-primary { color: $primary-color; font-size: $font-size-large; } .button-secondary { color: $secondary-color; font-size: $font-size-small; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using individual variables repeatedly | N/A | N/A | Higher due to larger CSS | [X] Bad |
| Using grouped maps for values | N/A | N/A | Lower due to smaller CSS | [OK] Good |