On this page
  1. Reflow, Repaint & Performance
  2. Contents
  3. Layout Thrashing (Forced Synchronous Layout)
  4. Compositor-Only Animations & requestAnimationFrame

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)

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

Linked from

Related notes