Performance: List group with badges
MEDIUM IMPACT
This affects the rendering speed and visual stability of list components with badges in the browser.
<ul class="list-group"> <li class="list-group-item d-flex justify-content-between align-items-center"> Messages <span class="badge bg-primary rounded-pill" style="min-width:2.5rem; text-align:center;">99+</span> </li> <li class="list-group-item d-flex justify-content-between align-items-center"> Notifications <span class="badge bg-primary rounded-pill" style="min-width:2.5rem; text-align:center;">1000</span> </li> <li class="list-group-item d-flex justify-content-between align-items-center"> Tasks <span class="badge bg-primary rounded-pill" style="min-width:2.5rem; text-align:center;">5</span> </li> </ul>
<ul class="list-group"> <li class="list-group-item">Messages <span class="badge bg-primary">99+</span></li> <li class="list-group-item">Notifications <span class="badge bg-primary">1000</span></li> <li class="list-group-item">Tasks <span class="badge bg-primary">5</span></li> </ul>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Variable width badges inside list items | Low (few nodes) | Multiple reflows on badge content change | Medium due to layout shifts | [X] Bad |
| Fixed width badges with flexbox layout | Low (few nodes) | Single reflow on initial render | Low paint cost due to stable layout | [OK] Good |