Networking
How a request reaches the server and back: DNS, TCP, TLS, HTTP messages and caching, HTTP/1.1 to HTTP/3, and what HTTPS protects, each with a live demo.
Every page, script, image and API call is a conversation over the network. The protocols are layered: IP moves packets between machines, TCP (or QUIC over UDP) turns them into a reliable stream, TLS encrypts that stream, and HTTP is the request-and-response language on top. Knowing what each layer costs explains most of what you see in the DevTools Network panel. Each topic below has a demo; some send real requests to this site.
How a request travels
Before the first byte of a page arrives, the browser has to find the server and agree how to talk to it. Each step is a round trip (RTT): a message there and an answer back, bound by distance and the speed of light, not bandwidth.
- Parse the URL, then DNS turns the host name into an IP address (cached by the browser, the OS and resolvers; see Origins, DNS and CORS).
- TCP handshake (SYN, SYN-ACK, ACK): one round trip to open a connection.
- TLS handshake for HTTPS: one round trip with TLS 1.3, two with TLS 1.2. HTTP/3 merges transport and TLS into one.
- Then the HTTP request: one more round trip plus the server's time. That total is the Time to First Byte.
- A reused (kept-alive) connection skips everything but the request, which is why browsers keep connections open and why
preconnecthelps.
Try it: count the round trips to the first byte (simulated)
Round trips
5
Time to first byte
550 ms
DNS lookup1 RTT · 0–100 ms
Ask a resolver for the server's IP address (often cached).
TCP handshake1 RTT · 100–200 ms
SYN → SYN-ACK → ACK; data can follow the ACK.
TLS 1.2 handshake2 RTT · 200–400 ms
Two round trips before any encrypted data.
Request → first byte1 RTT · 400–550 ms
One round trip plus 50 ms of server work.
Do: Serve from a CDN close to users and enable TLS 1.3 and HTTP/3;
preconnectto the few other origins you need early.Avoid: Spreading critical files over many domains: each new origin costs DNS, TCP and TLS again.
Read more:MDN: How browsers work(opens in a new tab)MDN: Overview of HTTP(opens in a new tab)
TCP: reliable, ordered, and careful
IP only does its best: packets can be lost, duplicated or arrive out of order. TCP numbers every byte, waits for acknowledgements, resends what is missing and hands the data over in order. UDP skips all that: no connection, no guarantees, less delay.
- Slow start: a new connection may send only about 10 packets (~14 KB) before waiting for an acknowledgement, then doubles each round trip. Small first responses arrive fastest.
- Loss is read as congestion: the window is cut in half and grows slowly again, so a lossy network hurts far more than its loss rate suggests.
- Head-of-line blocking: because data is delivered in order, one lost packet holds back everything after it until it is resent.
- UDP suits live audio and video, games and DNS, where late data is useless; QUIC builds its own reliability on UDP so it can avoid TCP's limits.
Try it: download a file through slow start (simulated)
Segments
351
Round trips (incl. handshake)
7
Time at 100 ms RTT
0.7 s
- Round 1: window 10, sent 10
- Round 2: window 20, sent 20
- Round 3: window 40, sent 40
- Round 4: window 80, sent 80
- Round 5: window 160, sent 160
- Round 6: window 320, sent 41
Red: a lost segment, so the window halves and then grows by one per round trip.
Do: Keep the critical HTML and CSS small enough to arrive in the first few round trips (the first ~14 KB matter most).
Avoid: Opening many fresh connections for small files: each starts slow again.
Read more:MDN: TCP(opens in a new tab)MDN: TCP slow start(opens in a new tab)MDN: Head-of-line blocking(opens in a new tab)
HTTP messages: methods, status codes, headers
HTTP is a text-shaped conversation: a request (method, path, headers, optional body) and a response (status code, headers, optional body). It is stateless: every request carries what the server needs, usually including a cookie or token.
- Methods:
GETreads (safe, cacheable),POSTcreates or acts,PUTreplaces,PATCHchanges part,DELETEremoves. GET, PUT and DELETE are idempotent: repeating them has the same effect, so they can be retried. - Status codes: 2xx success, 3xx redirect or cached, 4xx the client's fault, 5xx the server's. Return the precise one: 201 with a
Location, 401 vs 403, 404, 429 withRetry-After. - Headers carry the metadata:
Content-Type,Accept,Authorization,Cache-Control,Set-Cookie, CORS headers. fetch()only rejects on network failure; a 404 or 500 still resolves, so checkresponse.ok. It follows redirects for you.
Try it: send a real request and read the exchange
Send a request to see the real exchange.
Do: Check
response.okand the status, and show the user a specific message (see practice 4, Data Fetching Hook).Avoid: Answering 200 with { "error": … } in the body: caches, retries and monitoring all read the status code.
Read more:MDN: HTTP messages(opens in a new tab)MDN: Methods(opens in a new tab)MDN: Status codes(opens in a new tab)
HTTP caching
The fastest request is the one never sent. The server says with Cache-Control how long a response stays fresh; after that the browser revalidates it cheaply instead of downloading it again.
max-age=N: reuse without asking for N seconds.no-cache: may store, but must check first.no-store: never store (private data).privatekeeps it out of shared caches like CDNs.- Revalidation: the response carries an
ETag(orLast-Modified); the browser asks withIf-None-Match, and 304 Not Modified means "keep your copy", with no body. - Best pattern: hashed file names (
app.3f9c.js) withmax-age=31536000, immutable, and HTML withno-cacheso a deploy is picked up at once. - Scripts can't see a 304:
fetch()reports the cached 200. DevTools shows "(disk cache)" or 304.
Try it: fetch the same resource under three caching rules
Fetch each resource two or three times. These are real requests to this site.
Never store
Cache-Control: no-storeEvery request downloads it again.
Fresh for 5 minutes
Cache-Control: private, max-age=300Reused without asking until it is 5 minutes old.
Always check, reuse if unchanged
Cache-Control: no-cache + ETagAsks with If-None-Match; 304 means “keep your copy”.
Do: Give every response an explicit Cache-Control; long-lived for hashed assets, revalidated for HTML and API data.
Avoid: Leaving caching to defaults: browsers guess a freshness lifetime from Last-Modified (heuristic caching).
Read more:MDN: HTTP caching(opens in a new tab)web.dev: HTTP cache(opens in a new tab)
HTTP/1.1, HTTP/2 and HTTP/3
The meaning of HTTP hasn't changed since HTTP/1.1; what changed is how messages travel. Each version fixes the bottleneck of the one before.
- HTTP/1.1: text messages, one request at a time per connection. Browsers open up to 6 connections per host, which is why bundling and domain sharding were invented.
- HTTP/2: binary frames, many requests at once (multiplexing) on one connection, compressed headers (HPACK). But it still rides on TCP, so one lost packet stalls every stream.
- HTTP/3: runs on QUIC over UDP. Streams are independent, the handshake includes TLS, and connections survive a network change (Wi-Fi to mobile).
- With HTTP/2 and later, many small files are cheap again; bundle for caching and compression, not to save connections.
Try it: load twelve files with each version (simulated)
Connections
6
First file done
300 ms
All 12 files
400 ms
- file 1 · c1connection setup until 200 ms, downloaded 200–300 ms.
- file 2 · c2connection setup until 200 ms, downloaded 200–300 ms.
- file 3 · c3connection setup until 200 ms, downloaded 200–300 ms.
- file 4 · c4connection setup until 200 ms, downloaded 200–300 ms.
- file 5 · c5connection setup until 200 ms, downloaded 200–300 ms.
- file 6 · c6connection setup until 200 ms, downloaded 200–300 ms.
- file 7 · c1downloaded 300–400 ms.
- file 8 · c2downloaded 300–400 ms.
- file 9 · c3downloaded 300–400 ms.
- file 10 · c4downloaded 300–400 ms.
- file 11 · c5downloaded 300–400 ms.
- file 12 · c6downloaded 300–400 ms.
Measured: how this page really arrived (from the browser)
Reading…
Do: Enable HTTP/2 and HTTP/3 on your server or CDN, and serve the page and its files from as few origins as possible.
Avoid: Domain sharding under HTTP/2: extra connections defeat multiplexing and header compression.
Read more:MDN: HTTP/2(opens in a new tab)MDN: HTTP/3(opens in a new tab)
HTTPS and TLS
HTTPS is HTTP inside TLS. It gives three guarantees: confidentiality (nobody on the path can read it), integrity (nobody can change it unnoticed) and authenticity (you are talking to the real site).
- The server proves its identity with a certificate signed by a certificate authority your system trusts; the browser checks the name, the dates and the chain.
- The handshake agrees on fresh keys (forward secrecy): even a later key leak can't decrypt today's traffic.
- HSTS (
Strict-Transport-Security) makes the browser use HTTPS for the site from then on, so the first insecure redirect can't be attacked. - Browsers block mixed content (HTTP files on an HTTPS page) and keep powerful features (service workers, geolocation, the clipboard, passkeys) to secure contexts. HTTP/2 and HTTP/3 are only used over HTTPS.
Try it: what someone on the same network can read
| Part | They see | Example |
|---|---|---|
| IP addresses | Readable | 192.0.2.10 → 203.0.113.5needed to route packets |
| Host name | Readable | shop.examplefrom DNS and the TLS server name (SNI) unless both are encrypted |
| Sizes and timing | Readable | ~1.2 KB up, ~3 KB down, 80 mscan hint at what you did |
| Path and query | Readable | POST /account/login?next=/orders |
| Headers | Readable | User-Agent, Accept-Language, Referer… |
| Cookie | Readable | session=8f2c…stolen, it lets someone act as you |
| Body | Readable | email=ada@example.com&password=… |
Over HTTP anyone on the path can also change the page on the way: inject ads or scripts, or swap a download.
Measured: this page
Reading…
Do: Serve everything over HTTPS, redirect HTTP once, and send HSTS; mark cookies
Secure,HttpOnlyandSameSite.Avoid: Thinking HTTPS hides everything: the IP addresses, the host name and the size of the traffic still show.
Read more:MDN: TLS(opens in a new tab)MDN: Secure contexts(opens in a new tab)MDN: HSTS(opens in a new tab)web.dev: Why HTTPS matters(opens in a new tab)
Next: how these requests turn into a fast page in Performance.