Performance: CSS limitations that SASS solves
MEDIUM IMPACT
This concept affects the CSS authoring process and indirectly impacts page load speed by reducing CSS file size and complexity.
$border-radius: 0.5rem; $padding: 1rem; @mixin common-style { padding: $padding; border-radius: $border-radius; } .button { @include common-style; background-color: blue; color: white; } .card { @include common-style; background-color: white; box-shadow: 0 0 5px rgba(0,0,0,0.1); } .alert { @include common-style; background-color: red; color: white; }
/* Plain CSS with repeated code */ .button { background-color: blue; color: white; padding: 1rem; border-radius: 0.5rem; } .card { background-color: white; border-radius: 0.5rem; box-shadow: 0 0 5px rgba(0,0,0,0.1); padding: 1rem; } .alert { background-color: red; color: white; padding: 1rem; border-radius: 0.5rem; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeated CSS properties | N/A | N/A | Higher due to larger CSS file | [X] Bad |
| SASS with variables and mixins | N/A | N/A | Lower due to smaller CSS file | [OK] Good |