Performance: Why SASS improves responsive workflows
MEDIUM IMPACT
This affects how quickly and efficiently CSS for responsive design is written and maintained, impacting development speed and CSS bundle size.
$breakpoints: (small: 600px, medium: 900px, large: 1200px); @mixin respond($size) { @media (max-width: map-get($breakpoints, $size)) { @content; } } .box { width: 50%; @include respond(medium) { width: 75%; } @include respond(small) { width: 100%; } }
@media (max-width: 600px) { .box { width: 100%; } } @media (max-width: 900px) { .box { width: 75%; } } @media (max-width: 1200px) { .box { width: 50%; } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual media queries repeated | No extra DOM nodes | No extra reflows | Higher paint cost due to larger CSS | [X] Bad |
| SASS mixins and variables for media queries | No extra DOM nodes | No extra reflows | Lower paint cost due to smaller CSS | [OK] Good |