Performance: Alert and notification patterns
MEDIUM IMPACT
This affects how quickly alerts and notifications appear and update on the page, impacting user interaction speed and visual stability.
<div class="alert-container"> <div class="alert bg-red-500 text-white p-4 mb-4" aria-live="polite" role="alert">Error: Something went wrong!</div> </div> <script> setInterval(() => { const alert = document.querySelector('.alert'); alert.textContent = 'Error updated at ' + new Date().toLocaleTimeString(); }, 1000); </script>
<div class="alert-container"> <div class="alert bg-red-500 text-white p-4 mb-4">Error: Something went wrong!</div> </div> <script> setInterval(() => { const alert = document.querySelector('.alert'); alert.textContent = 'Error updated at ' + new Date().toLocaleTimeString(); alert.style.padding = '2rem'; // changing padding triggers reflow }, 1000); </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Changing layout styles on alert update | 1 text update + style change | 1 reflow per update | High paint cost due to layout shift | [X] Bad |
| Updating only text content with ARIA live | 1 text update | 0 reflows | Low paint cost, stable layout | [OK] Good |