Performance: Why custom functions are useful
MEDIUM IMPACT
Custom functions in Sass affect CSS generation speed and final CSS size, impacting page load and render time.
@function lighten-primary($amount) { @return lighten(#3498db, $amount); } .button { background-color: lighten-primary(10%); } .card { background-color: lighten-primary(10%); }
$primary-color: #3498db; .button { background-color: lighten($primary-color, 10%); } .card { background-color: lighten($primary-color, 10%); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeated calculations inline | N/A | N/A | Larger CSS size increases paint time | [X] Bad |
| Custom function reuse | N/A | N/A | Smaller CSS size reduces paint time | [OK] Good |