The Web FrontendDeeper

Kayavak / The Web Frontend / FE·19 Frontend Networking / Deeper

Deeper · The Web Frontend

Frontend Networking

The questions the chapter doesn't stop for: why this exists, the model to keep in your head, what changes when an assumption does, how sure we are of each claim, and what's still open. Read it after the chapter; back to the chapter.

Why does this exist?

HTTP/1.0 opened a new TCP connection for every request; pages with dozens of images paid a handshake each time. HTTP/1.1 (1997) kept connections open but still allowed one request at a time per connection, so browsers opened about six per host and sites spread assets across domains. Google's experimental SPDY (2009) multiplexed many requests over one connection and became HTTP/2 (2015). Its remaining weakness, that one lost TCP packet stalls every stream, led to QUIC and HTTP/3 (2022).

The browser's other networking rules came from security problems. Cookies (Lou Montulli at Netscape, 1994) gave the stateless web a memory, and were sent with every request to their site, which made cross-site request forgery possible; the SameSite attribute, with Lax as the default in Chrome from 2020, was the fix. The same-origin policy blocked useful cross-site APIs as well as attacks, so CORS (a W3C Recommendation in 2014) let servers opt in. For real-time updates, long polling gave way to WebSockets (2011) and server-sent events.

The mental model

Try it yourself first: write your own model in the Mental Model Explorer, then compare.

HTTP is a request–response contract whose meaning (methods, status codes, caching headers) has stayed the same for decades. The versions only change how those messages are packed onto connections.

Question Answer
What is it? The protocol, and the browser rules around it, by which pages fetch and send data
Problem it solves Moving data efficiently and safely between pages and servers, with caching and identity
Parts Semantics (methods, status, headers), versions (1.1, 2, 3), caching, cookies, CORS, real-time channels
How it works Requests carry a method and headers; responses say how long they may be reused; the browser enforces cross-origin rules
Assumptions GET is safe and cacheable; servers set correct cache and CORS headers
When they change A GET that changes data gets repeated by prefetchers and caches; wrong cache headers serve stale or private data
Where it fails Mobile networks (loss, latency), and anything relying on cookies being sent cross-site
Related ideas TCP, TLS and QUIC (Foundations, ch09); origins (ch12); security (ch28)

What if?

What if browsers sent cookies with every cross-site request, as they once did?

Reason it through, then open

Any page could submit a form to your bank and the request would arrive with your session cookie: cross-site request forgery. That was the default for most of the web's history; sites defended themselves with anti-CSRF tokens. SameSite cookies (Lax by default since 2020 in Chrome) stop the cookie travelling on cross-site sub-requests and form posts, removing most CSRF at the browser level.

What if HTTP had no caching?

Reason it through, then open

Every page view would re-download every script, image and font, and every CDN would be a plain proxy. Caching rules (max-age, validators like ETags, immutable for hashed files) are what let a returning visitor load a page from disk in milliseconds, and let CDNs absorb most traffic. The hard part is invalidation, which is why assets get content hashes in their names.

Where the boundary is

Aspect CORS CSRF protection
Protects The response: whether another origin's script may read it The server: against requests made with your credentials from another site
Enforced by The browser, using the server's headers The server (tokens) and the browser (SameSite)
Stops a request being sent? Mostly not: simple requests still reach the server Yes, that's its point
Confused because Both concern cross-origin requests; they guard opposite directions

How sure are we?

Claim How it's known Where from
HTTP/2 standardised in 2015, from SPDY Historical RFC 7540
HTTP/3 standardised in 2022 over QUIC Historical RFC 9114, RFC 9000
CORS doesn't stop simple requests reaching the server Convention Fetch Standard; it only hides the response
HTTP/3 is faster than HTTP/2 Measured, conditionally On lossy, high-latency networks mostly; on good networks the difference is small

Still open

Third-party cookies are being phased out unevenly: Safari and Firefox block them, while Chrome's plans have changed several times. How the web supports legitimate cross-site uses (embedded logins, federated identity) without tracking is unsettled.

What would change your mind? If HTTP/3 showed no benefit on real mobile networks, the complexity of a new transport wouldn't be worth it. Large deployments report gains mostly at the slow end.

Recall

What do HTTP versions change, and what stays the same?

Framing and transport change; semantics (methods, status codes, headers, caching) stay the same.

What does CORS protect?

Reading the response from another origin; it doesn't stop the request reaching the server.

How do SameSite cookies prevent CSRF?

Browsers don't send them on cross-site sub-requests and form posts (Lax), so forged requests arrive without the session.

Why did HTTP/3 move to QUIC?

HTTP/2 over TCP stalls every stream when one packet is lost; QUIC recovers per stream.

Reflect

Be honest with yourself; this stays in your browser. Anything you can't tick yet is what to revisit.