Performance: Accessing map values with map-get
This affects CSS preprocessing time, impacting initial page load speed.
$colors: (primary: #0055ff, secondary: #ff5500, accent: #00ffaa); $primary-color: map-get($colors, primary); $secondary-color: map-get($colors, secondary); $accent-color: map-get($colors, accent); .button { color: $primary-color; background-color: $secondary-color; border-color: $accent-color; }
$colors: (primary: #0055ff, secondary: #ff5500, accent: #00ffaa); .button { color: map-get($colors, primary); background-color: map-get($colors, secondary); border-color: map-get($colors, accent); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeated map-get calls inline | 0 (preprocessing only) | 0 | 0 | [X] Bad |
| Caching map-get results in variables | 0 (preprocessing only) | 0 | 0 | [OK] Good |
map-get($map, $key) do?map-getmap-get is designed to retrieve a value from a Sass map using a key."primary-color" from a Sass map $colors?$settings: ("font-size": 16px, "color": #333, "margin": 1rem);map-get($settings, "color") return?$theme: (primary: #0055ff, secondary: #ffaa00); $color: map-get($theme, "primary");
$themes: (
light: ("background": #fff, "text": #000),
dark: ("background": #000, "text": #fff)
);map-get?map-get($themes, dark), then get "text" from that map with map-get(..., "text").Pass the test and this pattern moves unknown