From URL to Pixels: What Modern Browsers Really Do Behind the Scenes
> Core intuition: In the 0.1 seconds after you press Enter, the browser has already done dozens of things — DNS lookup, TCP handshake, TLS negotiation, HTML parsing, CSS parsing, JavaScript compilation, DOM construction, style calculation, layout, paint, compositing. Yet most developers know nothing about these "black box" operations and end up guessing when optimizing performance. Addy Osmani — who wrote a browser at 16 and later led Chrome's Developer Experience team — lays it all out.
This post is a structured English summary of the original Chinese article, which is based on Addy Osmani's "How Modern Browsers Work."
Key points
- The classic interview answer (DNS → TCP → TLS → HTTP → DOM → CSSOM → render tree → layout → paint → composite) is a 1980s-era linear mental model. Modern browsers run dozens of speculative, parallel optimizations within ~200 ms.
- Preload scanner: while the HTML parser is blocked on a synchronous script, a separate scanner "peeks ahead" at the raw markup and starts downloading resources early — worth about 20% faster page loads in Chrome's experiments. It cannot execute JavaScript, so URLs generated dynamically in JS are invisible to it. Fix with static markup or
<link rel="preload">+fetchpriority="high". - Speculative loading: the Speculation Rules API lets Chrome prerender likely next pages (already used on Google Search results), making navigation feel instant.
- HTML parsing is a state machine with 80+ states defined by the HTML5 spec, built for fault tolerance on malformed markup.
- CSS is parsed as a context-free grammar: tokenization, then parsing into a rule tree. Unknown properties invalidate the entire declaration — order matters for vendor prefixes.
- Critical rendering path: synchronous JS blocks DOM construction; CSS blocks rendering; synchronous JS also blocks CSSOM construction. Hence "CSS in head, JS at end of body" is not dogma — it lets the browser build the render tree as early as possible.
- JIT compilation: all JS starts on Ignition (bytecode interpreter); hot code is promoted to TurboFan (optimizing compiler), with deoptimization when assumptions break (e.g., changed types).
- Hidden classes: objects with the same property shape share hidden classes; adding properties at runtime (like
p3.z = 7) forces new hidden classes and kills optimizations. Keep property creation order consistent; keep arrays single-typed. - Garbage collection: generational — Scavenge (fast, copying) for the young generation, Mark-Sweep-Compact for the old generation, mitigated by incremental marking and concurrent sweeping. Avoid churning temporary objects.
- Multi-process design: Browser process, sandboxed Renderer process per tab/site, GPU process, Network Service, utility processes — for security, performance, and isolation. Site Isolation gives each website (even inside iframes) its own renderer.
- Pipeline: JavaScript → Style → Layout → Layer → Paint → Composite.
- Cost hierarchy: layout changes (width, top, left) are most expensive; repaints (color, visibility) are medium; compositor-only changes (transform, opacity) are cheapest.
- Forced synchronous layout — interleaved reads (
offsetHeight) and writes in a loop — is a classic performance killer. Batch all reads, then all writes. - Keep the LCP element directly visible in HTML; never insert it via JS; use
fetchpriority="high". - Set explicit
width/heighton images and embeds to avoid layout shift. - Inline critical CSS; defer non-critical JS (
async/defer); code-split; lazy-load images; use WebP/AVIF; subset fonts. - Understand browser resource priorities (HTML, sync CSS, and fonts = Highest; prefetch = Lowest) and tune with
fetchpriority. - Addy Osmani, "How Modern Browsers Work," Medium, 2025
- Addy Osmani biography: https://addyosmani.com/bio/
- Ilya Grigorik, *High Performance Browser Networking* (O'Reilly)
- Chrome Developers Documentation: developers.google.com/web
- V8 Blog: v8.dev/blog
Parsing
V8 and JavaScript execution
Chrome's architecture and render pipeline
Performance guidance (Core Web Vitals)
| Metric | Measures | Target | |---|---|---| | LCP | Largest contentful element rendered | ≤ 2.5 s | | INP (formerly FID) | Interaction-to-next-paint latency | ≤ 200 ms | | CLS | Cumulative layout shift | ≤ 0.1 |
Practical checklist from the article:
The "70% problem"
Osmani's breakdown of common performance issues: unoptimized images (~30%), uncompressed JS/CSS (~20%), render-blocking resources (~15%), font loading strategy (~5%). Roughly 70% of performance problems are solved by basics, not advanced techniques.
Takeaway
> Don't fight the browser — work with its rules: keep critical resources visible in HTML, minimize reflow/repaint (prefer transform), control the number of critical resources, and respect resource priorities.
> "If you don't understand how the browser loads, parses, and renders your code, your optimizations are guesswork — and guesses are usually wrong." — Addy Osmani