Performance: Writing reusable CSS
MEDIUM IMPACT
This affects page load speed and rendering efficiency by reducing CSS size and minimizing style recalculations.
.btn { padding: 1rem; border-radius: 0.5rem; color: white; } .btn-primary { background-color: blue; } .btn-secondary { background-color: gray; }
.btn-primary { background-color: blue; color: white; padding: 1rem; border-radius: 0.5rem; } .btn-secondary { background-color: gray; color: white; padding: 1rem; border-radius: 0.5rem; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Duplicated styles in multiple classes | No extra DOM nodes | Multiple reflows due to repeated style recalculations | Higher paint cost due to inefficient styles | [X] Bad |
| Shared reusable classes for common styles | No extra DOM nodes | Single reflow for shared styles | Lower paint cost with efficient style application | [OK] Good |