Performance: @each loop over maps
MEDIUM IMPACT
This affects CSS generation time and the final CSS file size, impacting page load speed and render time.
$colors: (red: #f00, green: #0f0, blue: #00f); @each $name, $hex in $colors { .text-#{$name} { color: $hex; } .bg-#{$name} { background-color: $hex; } }
@each $color in (red, green, blue) { .text-#{$color} { color: $color; } } @each $color in (red, green, blue) { .bg-#{$color} { background-color: $color; } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Separate @each loops over lists | N/A (build time) | N/A | Larger CSS size delays style application | [X] Bad |
| Single @each loop over map | N/A (build time) | N/A | Smaller CSS size loads faster | [OK] Good |