Web Performance: Reflow and Repaint

Web Performance: Reflow and Repaint

3月 14, 2021 · 1 分钟阅读时长 · 107 字 · -阅读 -评论

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.

Alan H
Authors
开发者,数码产品爱好者,喜欢折腾,喜欢分享,喜欢开源