On this page
Reflow, Repaint & Performance
Prev: Critical Rendering Path | Up: rendering | Next: tutorials
Rel: Custom Properties & Animation, Observers & Web Workers
Ref: MDN Web Docs — Web Performance
Tags: #public #web #platform #rendering #performance
Contents
- > Layout Thrashing (Forced Synchronous Layout)
- > Compositor-Only Animations & `requestAnimationFrame`
Layout Thrashing (Forced Synchronous Layout)
Interleaving DOM writes (el.style.width = ...) with layout reads (el.offsetHeight, el.getBoundingClientRect()) inside a loop forces the browser to recompute layout synchronously on every iteration. Always batch reads first, then batch writes:
// Read phase
const heights = cards.map((card) => card.getBoundingClientRect().height);
const maxH = Math.max(...heights);
// Write phase
requestAnimationFrame(() => {
for (const card of cards) {
card.style.minHeight = `${maxH}px`;
}
});
Compositor-Only Animations & requestAnimationFrame
- Changing
width,height,top,margintriggers Layout -> Paint -> Composite. - Changing
color,background-color,box-shadowtriggers Paint -> Composite. - Changing
transformandopacityskips both Layout and Paint, running directly on the GPU Compositor. - Schedule visual JS updates inside
requestAnimationFrame()so they align cleanly with the display refresh cycle.
Linked from
- tuts/css
- tuts/css/properties/custom_properties_and_animation
- tuts/html/tutorials/media_and_responsive_images
- tuts/javascript/tutorials/event_loop_and_async_programming
- tuts/web/apis/observers_and_workers
- tuts/web/dom/nodes_and_elements
- tuts/web/rendering
- tuts/web/rendering/critical_rendering_path
- tuts/web/rendering/reflow_repaint_and_performance
- tuts/web/tutorials/devtools_and_debugging
Related notes
- tuts/web/rendering Linked here; links to this page; shared tags: #platform, #rendering, #web
- tuts/web/rendering/critical_rendering_path Linked here; links to this page; shared tags: #platform, #rendering, #web
- tuts/web/apis/observers_and_workers Linked here; links to this page; shared tags: #platform, #web
- tuts/css/properties/custom_properties_and_animation Linked here; links to this page; shared tags: #web
- tuts/web/dom/nodes_and_elements links to this page; shared tags: #platform, #web
- tuts/web/tutorials Linked here; shared tags: #platform, #web
- tuts/web/tutorials/devtools_and_debugging links to this page; shared tags: #platform, #web
- tuts/css links to this page; shared tags: #web
- tuts/html/tutorials/media_and_responsive_images links to this page; shared tags: #web
- tuts/javascript/tutorials/event_loop_and_async_programming links to this page; shared tags: #web