Performance: Responsive grid with breakpoints
MEDIUM IMPACT
This affects page load speed and rendering performance by controlling how many grid items and styles are applied at different screen sizes.
$breakpoints: (small: 600px, medium: 900px); .grid { display: grid; grid-template-columns: repeat(4, 1fr); @media (max-width: map-get($breakpoints, medium)) { grid-template-columns: repeat(2, 1fr); } @media (max-width: map-get($breakpoints, small)) { grid-template-columns: 1fr; } }
@media (max-width: 600px) { .grid-item { width: 100%; } } @media (max-width: 900px) { .grid-item { width: 50%; } } @media (min-width: 901px) { .grid-item { width: 25%; } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Multiple overlapping media queries with repeated widths | Low (grid container + items) | Multiple reflows on resize | Medium paint cost due to layout changes | [X] Bad |
| Single grid container with breakpoint variables and minimal media queries | Low (grid container + items) | Single reflow per breakpoint change | Lower paint cost due to efficient layout | [OK] Good |