Performance: Variable arguments in mixins
This affects CSS generation time and final CSS file size, impacting page load speed and rendering.
@mixin box-shadow($shadows) { box-shadow: $shadows; } .element { @include box-shadow(0 0 5px rgba(0,0,0,0.3)); }
@mixin box-shadow($shadows...) { box-shadow: $shadows; } .element { @include box-shadow(0 0 5px rgba(0,0,0,0.3), 0 0 10px rgba(0,0,0,0.2)); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Variable arguments with many values | No direct DOM impact | No direct reflows | Higher paint cost due to larger CSS | [!] OK |
| Single argument or limited values | No direct DOM impact | No direct reflows | Lower paint cost due to smaller CSS | [OK] Good |
...$args in a Sass mixin allow you to do?...$args syntax$args....$args to accept many inputs [OK]$args....$args... inside the mixin definition, which is the valid Sass syntax.$args... [OK]@mixin colors($colors...) {
@each $color in $colors {
.text-#{$color} {
color: $color;
}
}
}@include colors(red, blue, green);
$colors. It loops over each color and creates a CSS class with the color name and sets the text color.red, blue, green, it generates three classes: .text-red, .text-blue, and .text-green, each with the corresponding color style.@mixin padding($values...) {
padding: $values;
}@include padding(10px, 20px);, it outputs valid CSS padding values.padding: $values; serializes the list with spaces, producing valid CSS for shorthand properties like padding.margin: $values; for space-separated output; C loops creating multiple margin rules (invalid); D misuses unquote on list.Pass the test and this pattern moves unknown