Performance: Functions vs mixins comparison
MEDIUM IMPACT
This affects CSS generation size and browser rendering speed by controlling how styles are reused and output.
$shadow: 0 4px 6px rgba(0,0,0,0.1); .button { box-shadow: $shadow; } .card { box-shadow: $shadow; }
@mixin box-shadow() { box-shadow: 0 4px 6px rgba(0,0,0,0.1); } .button { @include box-shadow(); } .card { @include box-shadow(); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using mixins for repeated styles | No direct DOM impact | No direct reflows but larger CSS triggers slower style calculation | Higher paint cost due to larger CSS | [X] Bad |
| Using functions for value reuse | No direct DOM impact | No reflows triggered | Lower paint cost with smaller CSS | [OK] Good |