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
- Toggle CSS classes instead of frequently editing
style- Fewer reflow/repaint operations
- Avoid table layouts
- Smaller reflow/repaint scope
- Batch DOM operations (e.g.,
DocumentFragment) or use frameworks like React- Fewer reflow/repaint operations
- Debounce
window.resize- Fewer reflow/repaint operations
- Separate DOM reads from writes
- Mixed read/write forces layout flushes
- Use
will-change: transformwhen appropriate- Trade memory for speed
At a high level, skipping stages of the pipeline reduces total work and improves performance.

