The Lifecycle of a Web Request — From DNS to DOM

Team 7 min read

#network

#dns

#frontend

#performance

Introduction

When you type a URL into your browser and press Enter, a cascade of events unfolds behind the scenes. The journey starts with naming and resolution and ends with a fully constructed DOM ready for user interaction. Along the way, transport choices, caching decisions, and rendering optimizations shape not only correctness but perceived speed. This post walks through the lifecycle of a web request from DNS to the DOM, highlighting what happens at each step and why it matters.

DNS: Translating a URL to an IP

The first step in loading a page is resolving the domain name to an IP address. The browser asks a DNS resolver to translate the host in the URL (for example, example.com) into one or more IPs. The resolution process typically involves:

  • Querying DNS servers in a hierarchical order: root servers, then the top-level domain (TLD) servers (like .com), and finally the authoritative servers for the domain.
  • Receiving A or AAAA records (IPv4 or IPv6) that indicate where to reach the service.
  • Respecting TTLs (time-to-live) that tell caches how long a result can be reused. Most devices use a local resolver that caches prior results. If a cached entry exists and hasn’t expired, the browser can skip deep resolution steps. Modern networks can also use DNS over HTTPS (DoH) or DNS over TLS (DoT) to improve privacy and security during resolution.

DNS Caching and Resolution Path

DNS performance hinges on caching at multiple layers:

  • Browser cache: fast, local reuse of recently queried domains.
  • Operating system cache: shared across applications.
  • Resolver cache: the network or ISP caches results to serve future requests quickly.
  • Recursive vs. authoritative queries: root and TLD servers direct to the authoritative server for the domain, which responds with the definitive record. TTL values and DNS prefetching hints influence how aggressively results are cached and when pre-resolution occurs. In practice, domains behind CDNs may resolve to edge IPs that vary by location and time, complicating cache locality but reducing latency.

Establishing a Connection: Transport Layer

Once an IP is known, the browser must establish a transport path:

  • TCP: Traditional HTTP/1.1 uses a TCP connection. A three-way handshake (SYN, SYN-ACK, ACK) establishes reliability before data transfer.
  • TLS: For HTTPS, the TLS handshake begins to secure the channel. In TLS 1.3, the handshake is streamlined to minimize round-trips, with features like zero-round-trip (0-RTT) resumption in repeat visits.
  • QUIC/HTTP/3: Modern browsers may use QUIC (over UDP) to multiplex multiple streams with lower latency and faster handshakes. HTTP/3 controls are designed around QUIC’s connection characteristics. Connections may be reused across requests to the same host, reducing latency for subsequent assets. If a connection cannot be reused, a new handshake occurs.

The HTTP Request Lifecycle

With a transport path established, the browser crafts and sends the HTTP request:

  • Request line and headers: method (GET, POST, etc.), URL, and headers such as Host, Accept, User-Agent, and Accept-Encoding.
  • Redirects: if the server responds with a redirect (3xx), the browser may fetch the new URL, possibly after reusing or establishing a new connection.
  • Caching: conditional requests (If-Modified-Since, If-None-Match) allow the server to reply with 304 Not Modified to save bandwidth when a cached copy is still valid.
  • Parallelism: browsers often fetch multiple resources in parallel (or multiplex them under HTTP/2/3) to improve page load times.

The CDN and Edge Routing

Many sites are served through content delivery networks (CDNs). DNS may return an edge IP rather than the origin:

  • Edge servers host static assets and sometimes dynamic content, reducing distance and latency.
  • TLS termination often occurs at the edge, with the origin behind the edge cache.
  • Cache headers (Cache-Control, ETag) and CDN-specific features influence when assets are revalidated or purged. Edge caching improves responsiveness, but it introduces another layer of latency considerations when assets are not yet cached.

Server Processing and Response

Upon receiving the request, the server (origin or edge) processes it and returns a response:

  • Status codes indicate the result (200 OK, 301/302 redirects, 404/500 errors, etc.).
  • Headers convey metadata: Content-Type, Content-Length, Cache-Control, Vary, and Content-Encoding.
  • Content-Encoding (gzip, Brotli) compresses payloads to reduce transfer time.
  • Dynamic vs. static: static assets can be served quickly, while dynamic pages may trigger database queries, template rendering, or API calls.
  • Transfer methods: content can be delivered in a single response or streamed via chunked transfer for long-running responses or server-sent events.

Delivery of Assets and Parallel Requests

Modern pages include more than just HTML:

  • Resource loading order and parallelism matter for perceived performance.
  • HTTP/2 and HTTP/3 provide multiplexing, header compression, and better stream prioritization, enabling multiple assets to be fetched over a single connection.
  • Preconnect and prefetch hints help the browser establish connections or fetch resources that will be needed soon, improving load times.
  • Critical resources (CSS that blocks render, essential JavaScript) are often prioritized to minimize render delays.

The Browser’s Rendering Pipeline: From HTML to DOM

Once the HTML document begins arriving, the browser starts building the DOM:

  • Parsing: a tokenizer reads the HTML and emits tokens that form the DOM tree.
  • Script handling: synchronous scripts block parsing until execution finishes, while async/defer scripts allow parsing to continue.
  • Reflows: any DOM mutation or layout-affecting style change can trigger reflows, recalculating positions and sizes.

Constructing the Render Tree: CSSOM and DOM

CSS is parsed into a CSS Object Model (CSSOM) and combined with the DOM to form the render tree:

  • CSS rules determine visual styles for elements.
  • The render tree excludes non-visual elements like meta tags and script tags, focusing on boxes that will be painted.
  • Style recalculation occurs when CSS or DOM changes, potentially triggering additional layout passes.

Layout, Paint, and Composite

The render pipeline proceeds through three main stages:

  • Layout (reflow): computes geometry for each node in the render tree.
  • Paint: fills in pixels for visible elements, applying colors, borders, shadows, and images.
  • Composite: layers are combined into the final bitmap shown on screen, leveraging the GPU for smooth animations and scrolling.

JavaScript and User Interaction

JavaScript can significantly influence the lifecycle:

  • The event loop handles tasks, microtasks, and rendering work queues, scheduling work without blocking user input.
  • Scripts can modify the DOM, trigger layout or paint, and create asynchronous requests (fetch, Web Workers).
  • Blocking scripts delay parsing and rendering, so script placement and async/defer attributes are critical for performance.

Performance Considerations and Best Practices

A few practical takeaways to optimize the DNS-to-DOM path:

  • Minimize DNS lookups by coalescing hostnames where possible and reusing connections through HTTP/2/3.
  • Leverage DoH/DoT for privacy without sacrificing performance, and consider prefetching strategies for anticipated navigation.
  • Prefer HTTPS with TLS 1.3 for faster handshakes and secure transport, and use HTTP/3 when available for multiplexing advantages.
  • Optimize caching with sensible Cache-Control, ETag, and long-lived assets where appropriate to reduce repeated DNS/connection overhead.
  • Prioritize critical resources (CSS, above-the-fold JavaScript) to reduce render-blocking time and improve first paint.
  • Use responsive images and proper Content-Type handling to minimize unnecessary downloads and parsing work.
  • Monitor and tailor your CDN and edge configurations to balance latency, cache hit rate, and dynamic content delivery.

Conclusion

From the moment you press Enter to the instant your page renders, a symphony of DNS lookups, transport negotiations, server-side work, and client-side rendering plays out. Understanding this lifecycle helps you diagnose performance bottlenecks and design web experiences that load quickly and feel responsive. By optimizing DNS behavior, transport, caching, and the browser’s rendering path, you can make the journey from DNS to DOM as smooth as possible for your users.