Performance: Flexbox utility class generation
This affects page load speed and rendering performance by controlling how flexbox utility classes are generated and applied, impacting CSS size and browser layout calculations.
$flex-utilities: ( justify-content: (center, flex-start, flex-end), align-items: (center, flex-start), flex-direction: (row, column) ); @each $prop, $values in $flex-utilities { @each $value in $values { .#{$prop}-#{$value} { #{$prop}: #{$value}; } } }
@each $prop in (justify-content, align-items, flex-direction) { @each $value in (center, flex-start, flex-end, row, column) { .#{$prop}-#{$value} { #{$prop}: #{$value}; } } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Generating all possible flexbox utilities | No extra DOM nodes | No direct reflows but large CSS slows style calculation | Medium paint cost due to slower layout | [X] Bad |
| Generating only needed flexbox utilities | No extra DOM nodes | No direct reflows, smaller CSS speeds style calculation | Lower paint cost due to faster layout | [OK] Good |
.flex-row-center?
@mixin flex-utility($direction, $justify) {
display: flex;
flex-direction: $direction;
justify-content: $justify;
}
.flex-row-center {
@include flex-utility(row, center);
}@mixin flex-align($align) {
display: flex;
align-items: $align
}
.flex-align-center {
@include flex-align(center);
}.flex-row-start and .flex-column-center?Pass the test and this pattern moves unknown