Web Performance: Reflow and Repaint

A practical guide to reducing reflow/repaint in the browser pipeline, with actionable techniques and rationale.

Mar 14, 2021 · 1 min read · 107 Words · -Views -Comments · Programming
WebShell 🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

There are many ways to improve web performance: minify JS, reduce HTTP requests, use CDNs for critical assets, etc. Another lever is reducing reflow/repaint. Here’s a summary.

Rendering Pipeline

From Li Bing’s “Browser Working Principles and Practice”.

Techniques

  1. Toggle CSS classes instead of frequently editing style
    • Fewer reflow/repaint operations
  2. Avoid table layouts
    • Smaller reflow/repaint scope
  3. Batch DOM operations (e.g., DocumentFragment) or use frameworks like React
    • Fewer reflow/repaint operations
  4. Debounce window.resize
    • Fewer reflow/repaint operations
  5. Separate DOM reads from writes
    • Mixed read/write forces layout flushes
  6. Use will-change: transform when appropriate
    • Trade memory for speed

At a high level, skipping stages of the pipeline reduces total work and improves performance.

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover