URL to pixels: the whole lesson in words
The sale page's files are tiny, yet on a phone it stays blank for a moment.
Symptom
An agent built a sale page. Every file on it is tiny, yet on a phone the page stays blank for a moment. Nothing is broken. The time goes somewhere else.
A slow page with small files is waiting on something other than download size.
Predict
Before we explain anything, look at the page. It loads two stylesheets and a script from three other servers. Where does most of the wait go?
DNS lookup
First the browser needs the server's address. It asks DNS, the internet's directory, and waits for the answer. That is one round trip, unless the address is already cached.
Before connecting, the browser looks up the server's address with DNS.
TCP handshake
With the address, the browser opens a TCP connection. Both sides exchange a handshake before any data is sent. That is one more round trip.
A TCP connection costs a handshake, one round trip, before any data.
TLS handshake
The connection is then secured with TLS. In TLS 1.3 the two sides agree on keys in one round trip. Only now can the browser ask for the page.
TLS 1.3 adds one more round trip to secure the connection.
First byte
The request goes out and the first byte of HTML comes back. That makes four round trips. On a fast connection Chrome measured under a tenth of a second. At a phone's 150 millisecond round trip, the same four take 600.
Before the first byte: DNS, TCP, TLS and the request, about four round trips.
Three more origins
The HTML names three more servers. Each is a new origin, so each pays its own lookup and handshakes, side by side. When both stylesheets are in, the browser styles, lays out and paints.
Every new origin pays its own DNS, TCP and TLS before its first request.
Late origin
The font stylesheet names a fifth server, the one holding the font file. What does the browser do next?
Font file
It is a new origin, found late. Its lookup and handshakes only start once the font stylesheet is in, so the font arrives last, after the page has already painted.
An origin found late pays its round trips late, at the end of the chain.
Preconnect
Change one line: add a preconnect hint for the font server. The browser connects while the font stylesheet is still loading, so when the font is needed, the road is already open.
Preconnect moves a late origin's round trips earlier, in parallel with other work.
Agent bug
Back to the agent's page. Four other servers means four sets of round trips, and the font's server is found last. Serve the stylesheets and font from your own site, and preconnect to any origin you cannot avoid.
Fewer origins means fewer handshakes; preconnect the ones found late.
Recap
A URL becomes pixels through round trips: find the server, connect, secure, ask. Every new origin repeats them, and one found late adds them at the end.
URL → DNS → TCP → TLS → first byte → more origins → paint.
The common wrong idea
The browser downloads the page and shows it, so the wait is the size of the files.
What really happens
Before any byte arrives, the browser finds the server (DNS), connects (TCP) and secures the connection (TLS). Those are round trips, and every new origin pays them again.
The one-page cheatsheet for this lesson →
Sources
- developer.mozilla.org/en-US/docs/Web/Performance/Guides/How_browsers_work
- developer.mozilla.org/en-US/docs/Glossary/DNS
- developer.mozilla.org/en-US/docs/Glossary/TCP_handshake
- rfc-editor.org/rfc/rfc8446
- rfc-editor.org/rfc/rfc9000
- developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/rel/preconnect
- web.dev/articles/preconnect-and-dns-prefetch
- github.com/GoogleChrome/lighthouse/blob/main/docs/throttling.md
- developer.mozilla.org/en-US/docs/Web/API/Performance_API/Resource_timing