Critical Rendering Path (CRP)
The Critical Rendering Path is the sequential pipeline used by browser engines (V8/Blink, Gecko, WebKit) to convert HTML, CSS, and JS into physical pixels on screen.
1. The 5 CRP Pipeline Stages
- DOM Construction: Bytes -> Characters -> Tokens -> Nodes -> DOM Tree.
- CSSOM Construction: CSS bytes parsed into CSS Object Model.
- Render Tree: Combines DOM + CSSOM (excluding
display: nonenodes). - Layout (Reflow): Calculates exact viewport coordinates and bounding box dimensions.
- Paint & Composite: Fills pixels across raster layers and composites onto GPU.
2. Reflow vs Repaint Performance
- Reflow (Costly): Triggered by geometry changes (width, height, offsetTop). Recalculates layout for affected nodes and their descendants.
- Repaint (Cheaper): Triggered by visual changes (color, visibility). Updates pixels without recalculating dimensions.
- GPU Composite (Fastest): Properties like
transformandopacityrun directly on the GPU without triggering reflow or repaint!
The Challenge: Batch DOM Renderer
Implement batchDomOperations(container, items) using document.createDocumentFragment(). It must append element items to the fragment first, attach the fragment to container in one call, and return { usedFragment: true }.