Sub topic 3
From an HTML Response to a Rendered Page
Assume you know basic HTML and can run terminal commands. The browser does more than display the HTML response. It builds a document, fetches related resources, and turns the result into pixels.
From HTML response to rendered page
The browser parses HTML into a DOM (Document Object Model), a tree of elements. It parses CSS into rules and combines both into a render tree, which contains visible content. It then calculates layout, paints pixels, and runs JavaScript that can change the DOM or request more data.
Images, stylesheets, scripts, and fonts can trigger additional HTTP requests.
Cookies and sessions
HTTP is stateless: each request stands alone. A cookie is a small value that a browser stores and sends in later requests. A server can use a cookie containing a session identifier to look up login or shopping-cart data.
A cookie is sent with a Cookie request header. The server creates it with Set-Cookie. Attributes such as Secure, HttpOnly, and SameSite limit when the browser sends it.
Caching and conditional requests
A browser or intermediary can reuse a response instead of downloading it again. Cache-Control: max-age=3600 permits reuse for one hour. An ETag identifies a particular representation. After the cached copy becomes stale, the browser can send If-None-Match. The server returns 304 Not Modified when the copy is still current.
HTTP/1.1, HTTP/2, and HTTP/3
HTTP/1.1 commonly sends requests sequentially over a TCP connection. HTTP/2 uses one connection with multiplexed streams and compressed headers. HTTP/3 uses QUIC over UDP, reducing the impact of packet loss and avoiding some TCP connection delays. Applications still reason about requests, responses, headers, and status codes.
Same-origin policy and CORS
The same-origin policy restricts scripts from reading responses from a different scheme, host, or port. CORS (Cross-Origin Resource Sharing) allows a server to grant such access with headers such as Access-Control-Allow-Origin.
Proxies, load balancers, and CDNs
A reverse proxy receives traffic for an application. A load balancer distributes requests among servers. A CDN serves cacheable content from locations near users. These components can improve speed and availability, but they can also add cache, routing, and header-related failure points.
Inspecting traffic with curl and DevTools
curl -v https://example.com/The -v output shows connection details and request and response headers. In browser DevTools, the Network panel shows each request, timing, status, headers, cookies, and response body.
Exercise
A browser receives a cached response with ETag "v1". Which request header should it send to check whether the server's copy changed?
Show answer
It should send If-None-Match: "v1". The server can return 304 Not Modified if the representation is unchanged.