Performance: Progress bars
MEDIUM IMPACT
Progress bars affect rendering speed and interaction responsiveness, especially when animated or updated frequently.
<div class="progress"><div class="progress-bar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0" role="progressbar" style="width: 0%;">0%</div></div> <script> let lastValue = 0; function updateProgress(value) { if (value !== lastValue) { const bar = document.querySelector('.progress-bar'); bar.style.width = value + '%'; bar.setAttribute('aria-valuenow', value); bar.textContent = value + '%'; lastValue = value; } } setInterval(() => updateProgress(Math.floor(Math.random() * 100)), 100); </script>
<div class="progress"><div class="progress-bar" style="width: 0%;"></div></div> <script> function updateProgress(value) { const bar = document.querySelector('.progress-bar'); bar.style.width = value + '%'; bar.textContent = value + '%'; } setInterval(() => updateProgress(Math.floor(Math.random() * 100)), 50); </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Frequent width and text updates every 50ms | Multiple style and text updates | 20 reflows per second | High paint cost due to frequent changes | [X] Bad |
| Conditional width updates every 100ms without text changes | Minimal style updates | 10 reflows per second | Lower paint cost | [OK] Good |