Performance: Token-driven color palettes
MEDIUM IMPACT
This affects CSS rendering speed and style recalculations by controlling how colors are applied and reused across the site.
$color-primary: #3498db; $color-palette: ( primary: $color-primary, secondary: #2ecc71, accent: #e74c3c ); .button { background-color: map-get($color-palette, primary); } .card { border-color: map-get($color-palette, primary); } .alert { color: map-get($color-palette, primary); }
$primary-color: #3498db; .button { background-color: #3498db; } .card { border-color: #3498db; } .alert { color: #3498db; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Hardcoded repeated colors | No extra DOM nodes | Multiple reflows if colors change | Higher paint cost due to style thrashing | [X] Bad |
| Token-driven color palette | No extra DOM nodes | Single reflow on token change | Lower paint cost with stable styles | [OK] Good |