Performance: Spacing utility generation
MEDIUM IMPACT
This affects page load speed and rendering by controlling how CSS rules for spacing are generated and applied.
$spacing-scale: (0, 4, 8, 16, 24, 32, 48, 64); @each $space in $spacing-scale { .m-#{$space} { margin: #{$space}px; } .p-#{$space} { padding: #{$space}px; } }
@for $i from 0 through 100 { .m-#{$i} { margin: #{$i}px; } .p-#{$i} { padding: #{$i}px; } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Generating 101 spacing utilities with 1px increments | No extra DOM nodes | Triggers reflow on margin/padding changes | High paint cost if many elements use different classes | [X] Bad |
| Generating 8 spacing utilities with meaningful scale | No extra DOM nodes | Minimal reflows due to fewer classes | Lower paint cost with consistent spacing | [OK] Good |