Performance: Theming with mixins
MEDIUM IMPACT
This affects CSS generation size and browser style recalculation speed when themes change.
:root {
--color-primary: red;
--color-secondary: blue;
}
@mixin theme-colors {
color: var(--color-primary);
background-color: var(--color-secondary);
}
.button {
@include theme-colors;
}
/* Changing theme only updates CSS variables, no extra CSS generated */@mixin theme-colors($primary, $secondary) { color: $primary; background-color: $secondary; } .button { @include theme-colors(red, blue); } .card { @include theme-colors(green, yellow); } /* Repeated mixin calls generate duplicated CSS for each theme */
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeated mixin calls with hardcoded colors | None | None | High due to large CSS and style recalculations | [X] Bad |
| Mixin using CSS variables for colors | None | None | Low, minimal CSS size and fast style recalculation | [OK] Good |