Performance: Why expandable content saves space
MEDIUM IMPACT
Expandable content affects page load speed and visual stability by reducing initial content size and layout shifts.
<div class="accordion" id="accordionExample"> <div class="accordion-item"> <h2 class="accordion-header" id="headingOne"> <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne"> Expand to read more </button> </h2> <div id="collapseOne" class="accordion-collapse collapse" aria-labelledby="headingOne" data-bs-parent="#accordionExample"> <div class="accordion-body"> Lots of text and images hidden until user expands. </div> </div> </div> </div>
<div class="content">Lots of text and images fully visible on page load without any collapsing or hiding.</div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| All content visible on load | High (many nodes rendered) | 1 large reflow on load | High paint cost | [X] Bad |
| Expandable content collapsed initially | Low (fewer visible nodes) | Reflow only on expand | Lower paint cost initially | [OK] Good |