Performance: Default parameter values
This affects CSS compilation time and the final CSS bundle size, impacting page load speed.
@mixin button($color: black) { background-color: $color; } .button-primary { @include button(red); } .button-secondary { @include button(blue); } .button-default { @include button(); }
@mixin button($color) { background-color: $color; } .button-primary { @include button(red); } .button-secondary { @include button(blue); } .button-default { @include button(black); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No default parameters, repeated mixin calls with arguments | N/A | N/A | Larger CSS causes slower style calculation | [X] Bad |
| Default parameters used to avoid repetition | N/A | N/A | Smaller CSS improves style calculation speed | [OK] Good |
@mixin box($width: 100px, $height: 50px) { width: $width; height: $height; }.small { @include box($height: 30px); }@mixin card($bg-color blue) { background-color: $bg-color; }Pass the test and this pattern moves unknown