What the Critical Rendering Path really is
| Stage | What happens | Typical bottleneck |
|---|---|---|
| HTML parsing | DOM | Parser-blocking script |
| CSS parsing | CSSOM | Render-blocking stylesheet |
| Style + DOM | Render tree | Large style calculation scope |
| Layout | Geometry | Large DOM, repeated reflow |
| Paint / compositing | Pixels and layers | Large repaint or expensive effects |
MDN defines the Critical Rendering Path as the sequence of steps a browser uses to convert HTML, CSS and JavaScript into pixels. The core model includes the DOM, CSSOM, render tree, layout and paint. [1]
It is not a single metric or a single phase. CRP is a dependency model: what must be fetched, parsed and calculated before content can be shown.
It is also useful to separate first-render performance from later updates. A page can appear quickly yet still suffer from expensive layout, paint or JavaScript work during interaction.
From the HTML response to the DOM
After HTML arrives, the browser tokenizes the document and builds the DOM. MDN notes that DOM construction is incremental, allowing the parser to discover elements and resources before the whole document has downloaded. [1][2]
A high node count is not automatically a bug, but a very large DOM can increase the cost of later style and layout work. Optimize from measurements rather than an arbitrary element-count rule. [1]
For initial rendering, content near the top of the document and the dependencies discovered during parsing are especially important.
The preload scanner tries to get ahead of the parser
Modern browsers use an additional scanner that looks for references to resources such as CSS, scripts and images while the main parser is busy. This allows some requests to start earlier. [2]
The preload scanner cannot solve every dependency. Resources hidden behind JavaScript or revealed only after another file is processed may still be discovered late.
Critical resources should therefore be declaratively visible in HTML whenever practical. That is usually a stronger starting point than compensating later with many manual preloads.
CSSOM and render-blocking CSS
Critical and conditional stylesheets
<link rel="stylesheet" href="/en/css/main.css">
<link
rel="stylesheet"
href="/en/css/print.css"
media="print"
>
<link
rel="stylesheet"
href="/en/css/narrow.css"
media="screen and (width <= 480px)"
>
CSS determines how elements should be rendered. MDN describes CSS as render-blocking because the browser needs style information before it can correctly build the render tree and paint. [1][3]
An external <link rel="stylesheet"> in <head> is render-blocking by default. This does not mean every stylesheet should be inlined, but it makes the size and number of critical stylesheets important. [3]
Stylesheets that apply only under other conditions, such as media="print", can still download without blocking rendering for the current screen. [3]
DOM + CSSOM -> render tree
Once DOM and style information are available, the browser can build a render tree representing content that needs to be rendered together with computed styles. Elements hidden with display: none and their descendants are not represented in the render tree. [1]
The render tree is therefore not a direct copy of the DOM. Its purpose is to represent what actually needs layout and paint.
Optimizing DOM size without understanding styles and visibility can produce misleading conclusions. Measure the whole rendering pipeline.
Layout calculates geometry
During layout the browser determines element sizes and positions from the viewport, box model and relationships between elements. Resizing the viewport or changing geometry-affecting content and styles may require layout again. [1]
A large complex DOM can increase layout cost, especially when geometry calculations are repeatedly triggered during animation, scrolling or interactions. [1]
Layout itself is not an error. It is a normal rendering phase. The performance problem is excessive scope, frequency or forced timing.
Paint and compositing turn geometry into pixels
After geometry is known, the browser paints content. On subsequent updates, browsers generally repaint only affected regions, though complex styles and large areas can increase paint cost. [1]
Chrome DevTools provides Paint Flashing to show repainted areas and Layer Borders to inspect rendering layers. [14]
For animation, prefer approaches that avoid repeated layout and large repaint areas, but verify the actual bottleneck with a profile rather than assuming a CSS property is expensive.
JavaScript: parser blocking, defer, async and modules
Classic script, defer, async and module
<!-- Parser-blocking classic script -->
<script src="/js/legacy.js"></script>
<!-- Fetches in parallel, executes after HTML parsing -->
<script src="/js/app.js" defer></script>
<!-- Fetches in parallel, executes as soon as available -->
<script src="/js/analytics.js" async></script>
<!-- Module scripts are deferred by default unless async is used -->
<script type="module" src="/js/app.mjs"></script>
Under the HTML Standard, a classic external <script> without async or defer blocks further parsing while it is fetched and evaluated. defer fetches in parallel and evaluates after parsing; async evaluates as soon as the script is ready. [4]
Module scripts without async are deferred by default. Adding async allows the module graph to evaluate as soon as it is ready and removes ordering guarantees relative to other scripts. [4]
Application code that depends on the DOM usually fits defer or modules, while async is more suitable for independent code such as some analytics scripts.
Current MDN and Chrome guidance follows the same general rule: defer noncritical JavaScript and reduce or split main-thread work instead of executing everything before first render. [7][8]
Critical CSS: reduce blocking without creating a fragile hack
A small set of styles required for the first viewport can be inlined to avoid an extra request before first render. MDN lists critical CSS as a perceived-performance technique. [3]
Do not inline the entire application stylesheet. Large inline CSS increases HTML size, reduces cache reuse and can duplicate bytes across pages.
Use media conditions for styles not required in the current context, and be careful with dependency chains that delay discovering additional styles.
preload and modulepreload: fix discovery only where needed
Preloading a font and module
<link
rel="preload"
href="/en/fonts/brand.woff2"
as="font"
type="font/woff2"
crossorigin
>
<link
rel="modulepreload"
href="/en/js/dashboard.mjs"
>
rel="preload" declares a resource needed very early so its request can begin sooner. Preload itself does not execute a script; it fetches and caches the resource according to request parameters. [5]
rel="modulepreload" is designed for JavaScript modules. MDN notes that modules can be fetched, parsed, compiled and placed into the document's module map ahead of later evaluation. [6]
Do not preload everything. Excessive preloads compete for bandwidth with truly critical resources and can make performance worse. [5][6]
Critical Rendering Path and LCP
LCP is not the same thing as the Critical Rendering Path, but the two are closely connected. An LCP element cannot be presented while the browser is still waiting for resources or rendering prerequisites.
Chrome DevTools breaks LCP into TTFB, resource load delay, resource load time and element render delay. Render-blocking CSS, late resource discovery and heavy main-thread work can increase different parts of this timeline. [13]
For that reason, optimizing LCP should not stop at compressing the hero image. Inspect what actually delays rendering and when the critical resource was discovered.
content-visibility: skip work for large offscreen sections
Skipping rendering work for offscreen sections
.section-below-fold {
content-visibility: auto;
contain-intrinsic-size: auto 800px;
}
content-visibility: auto allows the browser to skip some layout and paint work for offscreen content until it becomes needed. MDN marks the feature as broadly available across current browsers since 2024. [9]
On long pages or complex views this can reduce initial rendering cost. contain-intrinsic-size can provide an estimated size to reduce layout shifts when skipped content becomes rendered. [9]
It is not always a replacement for pagination, virtualization or a simpler DOM. Use it where profiling shows meaningful offscreen rendering cost.
Runtime rendering: avoid interleaving layout reads and writes
Batching DOM reads and writes
// Avoid interleaving DOM reads and writes.
const cards = [...document.querySelectorAll(".card")];
// Read phase
const widths = cards.map((card) => card.getBoundingClientRect().width);
// Write phase
requestAnimationFrame(() => {
cards.forEach((card, index) => {
card.style.setProperty("--measured-width", `${widths[index]}px`);
});
});
After load, JavaScript can trigger additional style recalculation and layout. A particularly expensive pattern is repeatedly mixing geometry reads with DOM writes that invalidate layout.
In practice, batch reads and then batch writes. requestAnimationFrame() schedules a callback before the next repaint and is the right primitive for coordinating visual updates with the rendering cycle. [10]
MDN also advises against layout-affecting DOM changes from idle callbacks, since they can force recalculation after a frame's rendering work has already completed. [11]
Diagnosing the CRP in Chrome DevTools
| What to inspect | Where | What to look for |
|---|---|---|
| Render-blocking request | Performance / Network track | Marker, initiator, priority |
| Main thread | Performance | Long scripting, style, layout, paint |
| Repaint | Rendering -> Paint Flashing | Unexpectedly large repaint regions |
| Layout shift | Rendering / Performance | Which element moved and when |
| LCP | Performance Insights | Resource delay, load time, render delay |
The Performance panel can record page-load profiles, apply CPU and network throttling, and expose main-thread activity, requests, style, layout and paint. [12]
Render-blocking requests are marked in the Network track, and request details expose initiators plus initial and final priority. This helps distinguish slow transfer from late discovery and dependency ordering. [13]
The Rendering tab adds Paint Flashing, Layout Shift Regions, Layer Borders and frame-rendering statistics for visual confirmation of paint and layout behavior. [14]
Practical Critical Rendering Path checklist
Example: blocking head and a simpler alternative
<head>
<link rel="stylesheet" href="/en/css/all.css">
<script src="/js/vendor.js"></script>
<script src="/js/app.js"></script>
</head>
<!-- Better -->
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/en/css/critical.css">
<link rel="stylesheet" href="/en/css/print.css" media="print">
<script src="/js/app.js" defer></script>
</head>
First remove resources that should not be on the critical path at all. Only then tune priorities, preloads and CSS partitioning. Fewer critical dependencies mean fewer places where the browser can wait.
Do not apply one optimization template to every page. A content site, application dashboard and marketing landing page have different critical resources. Let DevTools show what blocks the actual view.
- Remove unused CSS and JavaScript from the initial path.
- Choose
deferorasyncdeliberately for classic scripts. - Remember that modules without
asyncare deferred by default. - Keep CSS that truly blocks first render as small as practical.
- Scope styles that are irrelevant to the current medium.
- Use
preloadandmodulepreloadonly for measurably critical resources. - Consider
content-visibility: autofor heavy offscreen sections on long pages. - Profile again after every change, including with CPU and network throttling.
