Performance: Multi-brand stylesheet generation
This affects page load speed and rendering by increasing CSS file size and complexity, impacting LCP and potentially causing slower style calculations.
Jump into concepts and practice - no test required
$brand-colors: ( brand1: #123456, brand2: #654321 ); :root { --primary-color: map-get($brand-colors, brand1); } // Use CSS variables and shared styles, override only brand-specific values
@each $brand in $brands { @import "brand-#{$brand}.scss"; } // Each brand file duplicates many common styles with minor changes
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Duplicated brand stylesheets | Low | Low | High due to large CSS | [X] Bad |
| Shared styles with CSS variables | Low | Low | Low | [OK] Good |
$brands to generate brand classes?@each to loop over maps with key and value variables.@each $brand, $colors in $brands, which is correct syntax for maps.$brands: (red: (primary: #f00), blue: (primary: #00f));
@each $brand, $colors in $brands {
.#{$brand} {
--main-color: #{$colors.primary};
}
}--main-color to the brand's primary hex color.$brands: (green: (primary: #0f0));
@each $brand, $colors in $brands {
.#{$brand} {
color: $colors-primary;
}
}$colors.primary, not dash.$brands. Which approach best ensures easy future updates and supports CSS variable overrides?