Performance: Responsive visibility toggling
MEDIUM IMPACT
This affects how quickly the page shows or hides content based on screen size, impacting initial load and layout stability.
<div class="hidden md:block">Menu content</div><div id="menu">Menu content</div> <script> function toggleMenu() { if(window.innerWidth < 768) { document.getElementById('menu').style.display = 'none'; } else { document.getElementById('menu').style.display = 'block'; } } window.addEventListener('resize', toggleMenu); toggleMenu(); </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| JS toggling visibility on resize | Multiple style changes | Many reflows on resize | High paint cost due to layout shifts | [X] Bad |
| Tailwind responsive visibility classes | No DOM changes | Single style recalculation | Low paint cost, stable layout | [OK] Good |