Lesson 8 of 12 · 11 min · How the browser works

How a web page loads: from URL to pixels

Covers: Current browser behaviour (Chromium, Firefox, Safari). Updated 13 Nov 2026. Part of the Frontend Developer roadmap.

What you will learn

  • The steps from entering a URL to a rendered page
  • DNS, TCP, TLS and HTTP in one sentence each
  • How the browser builds the DOM and CSSOM and a render tree
  • What blocks rendering, and how defer, async and type="module" change it
  • The role of caching and a common interview answer

In simple words

When you type an address and press Enter, a lot happens in under a second. The browser looks up where the website lives, connects securely, asks for the page, reads the instructions in the HTML, fetches the styles and scripts it mentions, and finally paints the result on screen. Knowing the steps tells you why a page is slow and where to fix it.

Words to know

  • DNS: the system that turns a name like example.com into a numeric address.
  • HTTP: the protocol browsers use to request pages and files from servers.
  • DOM: the browser's tree of objects built from the HTML.
  • Render-blocking: a resource the browser must finish loading before it can show the page.

The journey from URL to page

  1. Parse the URL: scheme (https), host (www.example.com), path (/learn/).
  2. Check caches: the browser cache, then the operating system, may already know the answer.
  3. DNS lookup: ask a DNS resolver for the server's IP address (cached for a while by the browser, the OS, and the resolver).
  4. TCP connection: a handshake to open a reliable connection to the IP address (HTTP/3 uses QUIC over UDP instead).
  5. TLS handshake: for https, agree on encryption and verify the server's certificate, so the connection is private and authentic.
  6. HTTP request: GET /learn/ HTTP/2 with headers (cookies, Accept-Language, User-Agent).
  7. Server processes the request (maybe a database query, a template), perhaps through a CDN or a load balancer, and sends an HTTP response: a status code (200), headers (Content-Type, Cache-Control) and the HTML.
  8. The browser parses the HTML as it streams in, and discovers more resources to fetch (CSS, JavaScript, images, fonts).
  9. Build the DOM and CSSOM, combine into a render tree, compute layout, paint and composite (the next lesson).

Each early step adds latency (waiting time), which depends on the round trips between the user and the server. A user in Hyderabad reaching a server in the US pays far more per round trip than one reaching a server in Mumbai or a nearby CDN edge, which is why hosting close to your users and using a CDN matter in India.

HTTP in a nutshell

An HTTP request has a method (GET, POST), a path, headers and sometimes a body. A response has a status code, headers and a body.

GET /learn/ HTTP/2
Host: www.example.com
Accept: text/html
Cookie: session=abc123

HTTP/2 200
Content-Type: text/html; charset=utf-8
Cache-Control: no-cache
Content-Encoding: br
...<html>...
  • HTTP/1.1 opens several connections and handles one request at a time per connection; HTTP/2 multiplexes many requests over one connection and compresses headers; HTTP/3 runs over QUIC and recovers faster on lossy mobile networks.
  • Content-Encoding: br or gzip compresses text files; always enable it.
  • Status code families: 2xx success, 3xx redirects (each redirect costs a round trip), 4xx client errors, 5xx server errors.

HTML parsing and the DOM

The browser reads the HTML incrementally and builds the DOM (Document Object Model), a tree of nodes that JavaScript can read and change:

html
├── head
│   ├── title
│   └── link (stylesheet)
└── body
    ├── h1
    └── p

While parsing, the preload scanner looks ahead in the raw HTML for resources (stylesheets, scripts, images) and starts downloading them early. This is why putting resources in the HTML (not creating them late with JavaScript) helps.

CSS and the CSSOM, and render blocking

The browser fetches each stylesheet and builds the CSSOM (CSS Object Model), the tree of style rules. It does not render anything until the CSSOM is ready for the content it has so far, because showing unstyled content that then changes would flash. So CSS is render-blocking. Keep the CSS needed for the first screen small and load it early: inline the critical CSS in <head> and load the rest asynchronously if needed, or just keep your total CSS lean.

JavaScript and the parser

A plain <script src="app.js"> is parser-blocking: HTML parsing stops while the script is downloaded and executed, because the script might change the DOM (document.write). It also waits for pending CSS, since scripts can query styles. Three ways to avoid blocking:

<script src="app.js" defer></script>       <!-- download in parallel, run after parsing, in order -->
<script src="analytics.js" async></script> <!-- download in parallel, run as soon as ready, any order -->
<script type="module" src="main.js"></script>   <!-- modules are deferred by default -->
Blocks parsing? Runs Order kept? Use for
plain <script> yes immediately yes rarely
defer no after the document is parsed, before DOMContentLoaded yes your app code
async no as soon as downloaded no independent scripts such as analytics
type="module" no deferred by default yes modern code

Place scripts at the end of <body> or use defer in <head> (preferred: the download starts earlier). Avoid heavy third-party scripts; they are a leading cause of slow pages.

The render tree and the first paint

The browser combines the DOM and CSSOM into a render tree (only visible elements with their computed styles: display: none is left out), computes the layout (size and position of every box), paints pixels, and composites layers onto the screen. The first moment anything appears is First Contentful Paint (FCP); the main content showing is Largest Contentful Paint (LCP).

Key events in the page lifecycle:

  • DOMContentLoaded: the HTML has been parsed and deferred scripts have run (images may still be loading).
  • load: everything, including images and stylesheets, has finished.

Resource hints

Tell the browser what it will need:

<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>   <!-- open the connection early -->
<link rel="dns-prefetch" href="https://cdn.example.com">
<link rel="preload" href="/fonts/Roboto.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" as="image" href="/img/hero.avif">                    <!-- the hero image -->
<link rel="prefetch" href="/next-page.js">                              <!-- low priority, for the next navigation -->

Use them sparingly; preloading too much competes with more important resources.

Caching

The fastest request is the one never made. Servers control caching with headers:

  • Cache-Control: max-age=31536000, immutable for files with a content hash in the name (app.3f9c2.js): cached for a year; deploying a new version changes the file name.
  • Cache-Control: no-cache for HTML: the browser may store it but must revalidate before using it (ETag or Last-Modified let the server answer 304 Not Modified with no body).
  • no-store for sensitive responses that must never be stored.
  • A CDN caches static files near users, a service worker can cache for offline use, and the back/forward cache restores pages instantly when users press Back (avoid patterns, such as unload handlers, that disable it).

The classic interview answer

"What happens when you type a URL?" A good answer follows the steps above: URL parsing, cache checks, DNS, TCP and TLS, HTTP request and response (through CDN, load balancer and application server), HTML parsing into the DOM, parallel fetching of CSS, JS and images, CSSOM, render tree, layout, paint and composite, with comments on what blocks rendering (CSS, synchronous scripts) and how to improve it (CDN, compression, caching, defer, critical CSS).

Seeing it yourself

In Chrome DevTools, the Network panel shows every request with a waterfall: DNS, connection, TLS, waiting (time to first byte), download. The Performance panel records the whole load and shows parsing, scripting, layout and paint on a timeline. Lighthouse gives an audit. Throttle the network to "Slow 4G" and the CPU to 4x slower to see what a mid-range phone experiences.

Common mistakes

  • Synchronous scripts in <head> that block rendering.
  • Many render-blocking stylesheets and huge CSS files.
  • No compression or caching headers.
  • Redirect chains (http to https to www to a path).
  • Loading everything up front, including third-party widgets.
  • Testing only on a fast laptop and fast Wi-Fi.

Try it yourself

  1. Open DevTools Network on a site, reload and find the HTML, the first CSS and JS requests; read the waterfall.
  2. Throttle to Slow 4G and note how First Contentful Paint changes.
  3. Add defer to a script in a test page and compare the Performance timeline.
  4. Check a site's response headers for Content-Encoding and Cache-Control.
  5. Write the "what happens when I type a URL" answer in your own words in two minutes.

Check yourself

What does DNS do?

It translates a hostname such as www.example.com into the IP address of the server.

Why is CSS render-blocking?

The browser avoids painting content before it knows its styles, to prevent a flash of unstyled content, so it waits for the CSSOM.

What is the difference between defer and async?

Both download without blocking the parser. defer runs scripts after parsing, in order; async runs each as soon as it is downloaded, in no guaranteed order.

Which header lets a browser reuse a file for a year without asking the server?

Cache-Control: max-age=31536000 (usually with immutable), on files with a content hash in the name.

Interview questions

What happens when you type a URL into the browser and press Enter?

The browser resolves the hostname via DNS, opens a TCP and TLS connection, sends an HTTP request, receives the HTML, parses it into the DOM while fetching CSS, scripts and images, builds the CSSOM, combines them into a render tree, lays out, paints and composites the page.

What is the critical rendering path?

The sequence of steps the browser takes to turn HTML, CSS and JavaScript into pixels. Optimising it means reducing the size and number of resources that block the first render and loading the rest later.

How do you stop JavaScript from blocking page rendering?

Use defer or type="module" for application scripts, async for independent ones, load non-critical scripts after the first render, and reduce JavaScript size.

Summary

  • A page load runs DNS, TCP, TLS, an HTTP request and response, then parsing, layout, paint and composite.
  • The browser builds the DOM and CSSOM; CSS and synchronous scripts block rendering.
  • Use defer, async and modules, resource hints, compression and cache headers; reduce round trips with a nearby CDN.
  • Measure with DevTools Network, Performance and Lighthouse on throttled connections.

Going deeper

See how much of this you can explain

A free mock interview asks you new questions on HTML, CSS and how the web works for Frontend Developer and scores every answer, with what to fix.