Performance: Vendor prefix mixin patterns
This affects CSS file size and rendering speed by controlling how many vendor-prefixed properties are generated and applied.
@mixin box-shadow($value) { box-shadow: $value; } .element { @include box-shadow(2px 2px 5px #000); }
@mixin box-shadow($value) { -webkit-box-shadow: $value; -moz-box-shadow: $value; box-shadow: $value; } .element { @include box-shadow(2px 2px 5px #000); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Mixin with all vendor prefixes | No extra DOM nodes | Triggers 1 reflow per style recalculation | Higher paint cost due to larger CSS | [X] Bad |
| Mixin with only standard property | No extra DOM nodes | Single reflow | Lower paint cost with smaller CSS | [OK] Good |
transform in Sass?@mixin user-select($value) {
-webkit-user-select: $value;
-moz-user-select: $value;
-ms-user-select: $value;
user-select: $value;
}
.button {
@include user-select(none);
}@mixin box-shadow($shadow) {
-webkit-box-shadow: $shadow;
-moz-box-shadow: $shadow
box-shadow: $shadow;
}display: flex and also sets flex-direction. Which is the best way to write this mixin?Pass the test and this pattern moves unknown