Performance: Design token management
Design token management affects CSS generation and runtime style recalculations, impacting page load speed and rendering consistency.
Jump into concepts and practice - no test required
$colors: ( primary: #007bff, secondary: #6c757d ); @function color($name) { @return map-get($colors, $name); } .button { color: color(primary); background-color: color(secondary); } // Centralized tokens with map and function
$primary-color: #007bff; $secondary-color: #6c757d; $primary-color: #0056b3; // redefining tokens multiple times .button { color: $primary-color; background-color: $secondary-color; } // Tokens scattered and redefined in many files
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Scattered and redefined tokens | No direct DOM impact | Triggers multiple style recalculations | Higher paint cost due to inconsistent styles | [X] Bad |
| Centralized tokens with Sass maps and functions | No direct DOM impact | Single style calculation on load | Lower paint cost with consistent styles | [OK] Good |
$primary-color: #3498db;. Others use JavaScript or invalid syntax.$font-size-base: 1.6rem;
$font-size-large: $font-size-base * 1.5;
body {
font-size: $font-size-large;
}$color-primary: #ff0000
$color-secondary: #00ff00;
.button {
background-color: $color-primary;
}