Reflow vs Repaint: Browser Performance Killers

Most developers know what Reflow and Repaint are.Very few know when they silently kill performance. Here’s the real breakdown 👇 🔁 Reflow — the expensive one Occurs when the browser recalculates layout, sometimes affecting the entire page, not just one element. Triggered by: • Reading offsetWidth, scrollTop, getBoundingClientRect() inside loops • Adding or removing DOM elements • Changing width, height, font-size • Window resize ⚠️ The silent killer: Layout Thrashing When you alternate DOM reads and writes in the same loop, the browser repeatedly forces layout recalculation, leading to major performance issues. 🎨 Repaint — the cheaper cousin Only redraws pixels while layout stays unchanged. Triggered by: • color • background-color • box-shadow • visibility Repaint is cheaper than reflow — but still not free on complex pages. 🚀 What actually improves performance • Batch DOM reads first, then writes • Use transform & opacity for animations (GPU-composited) • Use will-change: transform for frequently animated elements • Use Chrome DevTools Performance tab — large Layout blocks indicate costly reflows Reflow isn’t always avoidable, but triggering it blindly can hurt performance. The best frontend engineers don’t just write correct code — they write browser-aware code. #Frontend #WebPerformance #JavaScript #BrowserInternals #WebDevelopment #CSS

To view or add a comment, sign in

Explore content categories