Performance: Why reusable patterns matter
MEDIUM IMPACT
Reusable patterns reduce CSS duplication and DOM complexity, improving page load speed and rendering efficiency.
<style>
@layer components {
.btn-blue {
@apply bg-blue-500 text-white p-4 rounded;
}
}
</style>
<div class="btn-blue">Button 1</div>
<div class="btn-blue">Button 2</div>
<div class="btn-blue">Button 3</div><div class="bg-blue-500 text-white p-4 rounded">Button 1</div> <div class="bg-blue-500 text-white p-4 rounded">Button 2</div> <div class="bg-blue-500 text-white p-4 rounded">Button 3</div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeated utility classes inline | Multiple style recalculations | Multiple reflows if layout changes | Higher paint cost due to complexity | [X] Bad |
| Reusable Tailwind component class | Single style calculation reused | Minimal reflows | Lower paint cost | [OK] Good |