Free Ebook cover Web Servers 101: How HTTP, DNS, TLS, and Reverse Proxies Work

Web Servers 101: How HTTP, DNS, TLS, and Reverse Proxies Work

New course

13 pages

The Web Request/Response Lifecycle From URL to Page Render

Capítulo 1

Estimated reading time: 13 minutes

+ Exercise

What “URL to Page Render” Really Means

When you type a URL into a browser and press Enter, you’re starting a chain of coordinated actions across your device, the browser, the network, and one or more servers. The “request/response lifecycle” is the sequence of steps that turns that URL into pixels on your screen. In practice, it’s rarely a single request and a single response: the initial HTML response usually triggers additional requests for CSS, JavaScript, images, fonts, and API data. The browser also performs security checks, caching decisions, redirects, and rendering work (layout, paint, compositing) before you see a stable page.

This chapter focuses on the lifecycle at the browser and application level: how the browser decides what to request, how it processes responses, and how it turns those responses into a rendered document. It also explains what developers can observe and control in each stage.

Step 1: URL Parsing and Normalization

The browser first parses the URL into its components. Even small differences can change what gets requested and how it’s handled.

  • Scheme: https vs http affects security requirements and defaults (like port).
  • Host: the domain name (e.g., www.example.com).
  • Port: often implicit (443 for HTTPS, 80 for HTTP) unless specified.
  • Path: e.g., /products/123.
  • Query string: e.g., ?ref=ad&sort=price.
  • Fragment: e.g., #reviews (handled client-side; not sent to the server in the HTTP request).

The browser may normalize the URL (for example, adding a trailing slash in some cases, punycode conversion for international domains, or encoding special characters). It also decides whether the input is a search query or a URL based on heuristics and settings.

Step 2: Choosing a Navigation Type and Context

Not all navigations are equal. The browser determines whether this is:

Continue in our app.

You can listen to the audiobook with the screen off, receive a free certificate for this course, and also have access to 5,000 other free online courses.

Or continue reading below...
Download App

Download the app

  • Top-level navigation: typing a URL, clicking a link, or using bookmarks.
  • Same-document navigation: changing only the fragment (e.g., #section) typically does not trigger a network request.
  • History navigation: back/forward may use cached pages (including back-forward cache) rather than reloading.
  • Reload: may revalidate cached resources or bypass cache depending on the reload type.

This matters because it influences caching behavior, whether the browser can reuse an existing document, and how aggressively it will fetch resources.

Step 3: Cache Lookup Before Network

Before making a network request, the browser checks caches. There are multiple layers:

  • HTTP cache: stores responses keyed by URL (and sometimes additional headers) according to caching rules.
  • Service Worker cache (if a Service Worker is installed): can intercept requests and respond from its own cache or generate responses.
  • Memory cache: short-lived cache for resources used recently in the same session.

If a cached response is fresh, the browser can use it immediately. If it’s stale but revalidatable, the browser may send a conditional request (using headers like If-None-Match or If-Modified-Since) to ask the server whether the cached copy is still valid. A 304 Not Modified response tells the browser to reuse the cached body.

Practical example: observing cache behavior

In browser DevTools (Network tab), you can often see statuses like “(from disk cache)” or “(from memory cache)”, and you can compare a normal reload with a “hard reload” that bypasses cache. This is one of the fastest ways to understand why a page feels instant sometimes and slow other times.

Step 4: Establishing a Connection (or Reusing One)

If the browser needs the network, it must send the request to the server. For performance, browsers try to reuse existing connections to the same origin (scheme + host + port). If a connection already exists and is healthy, the request can be sent immediately.

If not, the browser opens a new connection. Modern browsers may also use connection coalescing (reusing a single HTTP/2 or HTTP/3 connection for multiple hostnames when allowed) and may preconnect to likely-needed origins based on hints or past behavior.

From the lifecycle perspective, the key point is that connection setup can be a significant portion of total time, especially on mobile networks. Reuse and early connection strategies reduce that overhead.

Step 5: Building the HTTP Request

The browser constructs an HTTP request based on the navigation and context. For a typical page load, the initial request is usually a GET for the document.

Common request elements

  • Method: GET for navigation, sometimes POST for form submissions.
  • Request headers: include metadata such as accepted content types, language preferences, compression support, cookies, and caching validators.
  • Cookies: automatically attached for the target origin (subject to cookie rules like SameSite).
  • Request body: typically empty for GET, present for POST/PUT.

For navigations, the browser may also send headers that help the server respond appropriately, such as indicating it expects HTML and that the request is for a document rather than an image or script.

Example of a simplified document request

GET /products/123?ref=ad HTTP/1.1
Host: www.example.com
Accept: text/html,application/xhtml+xml
Accept-Encoding: gzip, br
Accept-Language: en-US,en;q=0.9
Cookie: session=abc123
User-Agent: ...

Real requests include more headers, but this shows the idea: the browser tells the server what it wants and what it can handle.

Step 6: Receiving the Response and Handling Status Codes

The server responds with a status code, headers, and (usually) a body. The browser uses the status code to decide what to do next.

Key status code behaviors during navigation

  • 200 OK: the browser processes the response as the requested document.
  • 301/302/307/308 Redirect: the browser makes a new request to the Location URL. Redirect chains add latency and can change method behavior depending on the code.
  • 304 Not Modified: the browser uses its cached body and applies updated headers.
  • 401/403: may show an error page or trigger authentication flows depending on context.
  • 404/500: typically results in an error page (which may still be a valid HTML document returned by the application).

Redirects are especially important in the lifecycle because they can change the origin, which affects cookies, caching, and which connections can be reused. A common example is redirecting http:// to https://, or redirecting a bare domain to www (or the reverse).

Step 7: Content-Type, Encoding, and Streaming

Once the browser begins receiving the response body, it decides how to interpret it based on headers such as Content-Type and Content-Encoding.

  • Content-Type tells the browser whether it’s HTML, CSS, JavaScript, JSON, an image, etc.
  • Content-Encoding indicates compression (like gzip or brotli) that must be decompressed before parsing.
  • Character encoding (charset) affects how bytes become text. HTML can also declare charset in a meta tag.

HTML documents are often streamed: the browser can start parsing and rendering parts of the page before the entire response has downloaded. This is why the order of tags in HTML matters for performance and behavior.

Step 8: HTML Parsing and DOM Construction

As HTML bytes arrive, the browser tokenizes and parses them into a tree structure called the DOM (Document Object Model). The DOM represents elements, attributes, and text nodes.

During parsing, the browser may discover subresources that it needs to fetch, such as:

  • <link rel="stylesheet" href="..."> for CSS
  • <script src="..."> for JavaScript
  • <img src="..."> for images
  • <link rel="preload"> hints for critical resources

Each discovered resource can trigger additional HTTP requests, often in parallel, subject to browser limits and prioritization rules.

Parser blocking and scripts

Some resources affect how parsing proceeds:

  • Classic scripts without attributes can block HTML parsing because the browser must fetch and execute them before continuing (since they can modify the document during parsing).
  • defer scripts download in parallel but execute after parsing completes, before the DOMContentLoaded event.
  • async scripts download in parallel and execute as soon as they’re ready, which can interrupt parsing.

Understanding these behaviors helps you predict why a page may appear blank longer than expected or why certain elements aren’t available when scripts run.

Step 9: CSS Parsing, CSSOM, and Render-Blocking

CSS is parsed into another structure often referred to as the CSSOM (CSS Object Model). The browser combines the DOM and CSSOM to determine computed styles for each element.

Stylesheets are typically render-blocking: the browser delays painting content until it has enough CSS to avoid showing unstyled content or reflowing repeatedly. This is why critical CSS is often prioritized and why large CSS files can delay first paint.

Inline CSS in the HTML can be applied immediately, while external stylesheets require additional network requests.

Step 10: Layout, Paint, and Compositing

Once the browser has DOM and CSSOM, it can build a render tree (a representation of visible elements) and perform:

  • Layout (reflow): computing sizes and positions of elements based on the viewport and CSS rules.
  • Paint: drawing pixels for backgrounds, text, borders, images, etc.
  • Compositing: assembling painted layers into the final image, often using the GPU for efficiency.

Rendering is incremental. The browser may paint parts of the page while other resources are still loading. Later changes (like loading a web font or inserting content via JavaScript) can trigger additional layout and paint work.

Practical example: why layout shifts happen

If an image loads without known dimensions, the browser may initially lay out the page without reserving the correct space. When the image arrives, the layout changes and content moves. Providing width/height attributes or CSS aspect ratios allows the browser to reserve space and reduce unexpected shifts.

Step 11: JavaScript Execution and the Event Loop

JavaScript can run at multiple points in the lifecycle: during parsing (for blocking scripts), after parsing (deferred scripts), or whenever async scripts finish downloading. JavaScript can:

  • Modify the DOM (adding/removing elements, changing text)
  • Change styles (class toggles, inline styles)
  • Trigger network requests (fetching API data)
  • Register event handlers (click, scroll, input)

The browser runs JavaScript on the main thread alongside many rendering tasks. Long-running scripts can delay input responsiveness and delay rendering updates because the main thread is busy.

Key lifecycle events you’ll see in code

  • DOMContentLoaded: fires when the initial HTML has been parsed and the DOM is built (but subresources like images may still be loading).
  • load: fires when the document and its dependent resources (images, stylesheets, etc.) have finished loading.

These events are often used to decide when it’s safe to query DOM elements or start non-critical work.

Step 12: Additional Requests Triggered by the Page

After the initial HTML response, most modern pages make more requests:

  • Static assets: CSS, JS bundles, images, fonts, icons.
  • API calls: JSON data for product lists, user profiles, search results.
  • Analytics and third-party scripts: can add extra network and CPU work.

These requests follow the same general request/response pattern, but they may have different priorities. For example, the browser often prioritizes resources needed for rendering above resources that are not immediately visible.

Practical step-by-step: tracing a page load in DevTools

  • Open DevTools and go to the Network tab.
  • Enable “Preserve log” to keep requests across redirects.
  • Reload the page.
  • Click the first document request (usually the HTML). Inspect the headers, status code, and timing breakdown.
  • Sort by “Priority” or “Waterfall” to see which resources block rendering.
  • Click a CSS or JS file and confirm whether it was cached, compressed, and how long it took to download.
  • Look for redirect chains (multiple document requests before the final HTML).

This workflow helps you connect what you see on screen (blank page, partial render, late-loading images) to the underlying network and parsing behavior.

Step 13: Client-Side Routing and Single-Page Applications (SPAs)

In traditional multi-page sites, each navigation loads a new HTML document. In SPAs, the initial navigation loads a shell HTML document and JavaScript application code. After that, clicking links may not trigger full document navigations. Instead:

  • The app intercepts navigation events.
  • The URL changes via the History API.
  • The app fetches data (often JSON) and updates the DOM dynamically.

From the user’s perspective, it still feels like navigating pages, but from the network perspective, many navigations become API requests plus DOM updates rather than full HTML document loads.

Practical implication

If a page “loads” quickly but content appears late, it may be because the HTML shell is small and fast, while the JavaScript bundle and API calls determine when meaningful content appears.

Step 14: Server-Side Rendering (SSR), Hydration, and Streaming HTML

Some applications render HTML on the server (SSR) to show meaningful content earlier. The browser receives HTML that already contains the page structure and text, then downloads JavaScript that “hydrates” the page by attaching event handlers and making the UI interactive.

  • SSR benefit: faster first meaningful paint because HTML contains real content.
  • Hydration cost: the browser must execute JavaScript to make the page interactive; heavy hydration can delay responsiveness.

Some systems also stream HTML in chunks so the browser can start rendering earlier, while the server continues generating the rest of the page.

Step 15: Security and Policy Checks That Affect Rendering

Even when the network and parsing steps succeed, the browser enforces security policies that can block or modify resource loading:

  • Mixed content rules: an HTTPS page may block or restrict loading of HTTP subresources.
  • Content Security Policy (CSP): can block inline scripts, restrict script origins, and prevent certain resource loads.
  • CORS: affects whether JavaScript can read responses from other origins (it doesn’t usually block loading a script tag, but it can block fetch/XHR reads).

These checks can lead to situations where the HTML loads but scripts fail, resulting in a page that renders partially or lacks interactivity.

Step 16: Putting It All Together With a Concrete Walkthrough

Consider navigating to https://shop.example.com/products/123. A typical lifecycle might look like this:

  • The browser parses the URL, identifies it as an HTTPS document navigation, and checks caches.
  • If no fresh cached HTML exists, it sends a GET request for /products/123.
  • The response returns 200 with Content-Type: text/html and compressed body.
  • The browser starts parsing HTML immediately and discovers main.css and app.js.
  • It requests main.css (render-blocking) and app.js (maybe deferred).
  • Once enough CSS is available, the browser computes styles, performs layout, and paints the initial view.
  • JavaScript executes, attaches event handlers, and triggers an API request to /api/product/123 to fetch live inventory and recommendations.
  • When API data arrives, JavaScript updates the DOM; the browser recalculates layout for affected sections and repaints.
  • Images load progressively; if dimensions were not reserved, layout shifts may occur; otherwise, images fill in without moving content.

This is the core pattern you’ll see across most sites: an initial document request, followed by a burst of subresource requests, then incremental rendering and interactivity as scripts and data arrive.

Now answer the exercise about the content:

In a typical page load, why might changing only the URL fragment (for example, moving from a page to #section) not trigger a network request?

You are right! Congratulations, now go to the next page

You missed! Try again.

The fragment (the part after #) is processed by the browser on the client side. It is not included in the HTTP request, so changing only the fragment typically results in a same-document navigation without a network request.

Next chapter

URLs and Origins: Scheme, Host, Port, Path, Query, and Fragments

Arrow Right Icon
Download the app to earn free Certification and listen to the courses in the background, even with the screen off.