Performance: Recursive mixins
MEDIUM IMPACT
This affects CSS compilation time and the size of the generated CSS, impacting page load speed and rendering performance.
@mixin recursive-good($n) { @for $i from 1 through $n { .level-#{$i} { color: red; } } } @include recursive-good(10);
@mixin recursive-bad($n) { @if $n > 0 { .level-#{$n} { color: red; @include recursive-bad($n - 1); } } } @include recursive-bad(10);
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Recursive mixin with deep nesting | N/A (CSS only) | N/A | High due to complex selectors | [X] Bad |
| Loop-based mixin generating flat CSS | N/A (CSS only) | N/A | Low due to simple selectors | [OK] Good |