Performance: List values and operations
MEDIUM IMPACT
This affects CSS preprocessing speed and the size of the generated CSS, impacting initial page load and style calculation.
$colors: red, blue, green, yellow, orange, purple, black, white; $color1: nth($colors, 1); $color2: nth($colors, 2); $color3: nth($colors, 3); $color4: nth($colors, 4); $color5: nth($colors, 5); $color6: nth($colors, 6); $color7: nth($colors, 7); $color8: nth($colors, 8); .element { color: $color1; background-color: $color2; border-color: $color3; box-shadow: 0 0 5px $color4; outline-color: $color5; fill: $color6; stroke: $color7; caret-color: $color8; }
$colors: red, blue, green, yellow, orange, purple, black, white; .element { color: nth($colors, 1); background-color: nth($colors, 2); border-color: nth($colors, 3); box-shadow: 0 0 5px nth($colors, 4); outline-color: nth($colors, 5); fill: nth($colors, 6); stroke: nth($colors, 7); caret-color: nth($colors, 8); }
| Pattern | Sass Compile Time | CSS Size | Browser Style Calculation | Verdict |
|---|---|---|---|---|
| Repeated nth() calls on long list | High (multiple traversals) | Medium (same CSS size) | Medium (normal CSS complexity) | [X] Bad |
| Extract list values once to variables | Low (single traversal per value) | Medium (same CSS size) | Medium (normal CSS complexity) | [OK] Good |