Performance: Progress bars
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 |
progress bar in Bootstrap?progress, not progress-bar which is the inner bar.<div class='progress'></div> uses progress which is correct. The other options use incorrect or non-existent classes.<div class='progress'> <div class='progress-bar bg-success' role='progressbar' style='width: 75%;'>75%</div> </div>
progress-bar and bg-success which makes it green. The style sets width to 75%.<div class='progress'> <div class='progress-bar' role='progressbar' style='width: 50%;>50%</div> </div>
style='width: 50%;> which misses the closing single quote before the closing angle bracket.progress-bar and role attribute are correct. Width 50% is valid.progress-bar-striped and progress-bar-animated. The color class for blue is bg-primary.<div class='progress'><div class='progress-bar bg-primary progress-bar-striped progress-bar-animated' role='progressbar' style='width: 40%;'>40%</div></div> uses all correct classes and structure inside a progress container. The other options use incorrect or missing class names or wrong container structure.Pass the test and this pattern moves unknown