Performance: Spinner components
Spinner components affect the page's interaction responsiveness and visual stability during loading or async operations.
<div class="spinner-border" role="status"><span class="visually-hidden">Loading...</span></div>
<div class="spinner-border" role="status"><span class="visually-hidden">Loading...</span></div><script>setInterval(() => { document.querySelector('.spinner-border').style.transform = `rotate(${Date.now() % 360}deg)`; }, 10);</script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| JS-driven spinner rotation | Minimal DOM nodes | Multiple reflows per frame (~100 per second) | High paint cost due to frequent style changes | [X] Bad |
| Bootstrap CSS spinner | Minimal DOM nodes | No reflows during animation | Low paint cost, GPU accelerated | [OK] Good |
spinner-border and spinner-grow.spinner-border creates a spinner with a border style.<div class="spinner-grow text-primary" role="status"> <span class="visually-hidden">Loading...</span> </div>
spinner-grow class creates a growing spinner animation. The text-primary class applies Bootstrap's primary blue color.role="status" helps screen readers. The span with visually-hidden hides the text visually but keeps it accessible.<div class="spinner-border" aria-label="Loading"> <span>Loading...</span> </div>
span with visually-hidden class inside spinners to provide accessible text for screen readers.span inside the spinner lacks the visually-hidden class, so the text is visible visually, which is not ideal.spinner-grow is the correct class.text-danger class applies the red color. The role="status" and span with visually-hidden provide accessible loading text.spinner-grow, text-danger, role="status", and hidden accessible text correctly.Pass the test and this pattern moves unknown