Performance: Generating utility classes with loops
MEDIUM IMPACT
This affects CSS file size and browser style calculation time, impacting page load and rendering speed.
@for $i from 1 through 10 { .m-#{$i} { margin: #{$i}rem; } }
@for $i from 1 through 1000 { .m-#{$i} { margin: #{$i}px; } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Generating 1000 utility classes with px units | No extra DOM nodes | No reflows triggered by CSS alone | High paint cost due to large CSS and style calculation | [X] Bad |
| Generating 10 utility classes with rem units | No extra DOM nodes | No reflows triggered by CSS alone | Low paint cost due to small CSS and fast style calculation | [OK] Good |