URL to pixels in one screen

The one-page summary of the lesson URL to pixels. It states the answers, so if you want them to stick, play the lesson first: it makes you predict before it explains.

The points

  • DNS turns the host name into an address: about one round trip unless cached.
  • TCP opens the connection with a handshake: one round trip.
  • TLS 1.3 secures it: one more round trip. Then the request: another.
  • Every new origin repeats DNS, TCP and TLS before its first request.
  • With HTTP/3, one QUIC handshake does the work of TCP and TLS together.
  • An origin found late (a font named in CSS) starts its setup late.
  • Fix: fewer origins; preconnect, with crossorigin for fonts, to origins found late.

What catches people out

  • Preconnecting to an origin already named in the HTML gains nothing.
  • A font preconnect without crossorigin only does the DNS lookup.

The wrong idea, and the right one

Often believed: 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.

Step by step

  1. Symptom. A slow page with small files is waiting on something other than download size.
  2. DNS lookup. Before connecting, the browser looks up the server's address with DNS.
  3. TCP handshake. A TCP connection costs a handshake, one round trip, before any data.
  4. TLS handshake. TLS 1.3 adds one more round trip to secure the connection.
  5. First byte. Before the first byte: DNS, TCP, TLS and the request, about four round trips.
  6. Three more origins. Every new origin pays its own DNS, TCP and TLS before its first request.
  7. Font file. An origin found late pays its round trips late, at the end of the chain.
  8. Preconnect. Preconnect moves a late origin's round trips earlier, in parallel with other work.
  9. Agent bug. Fewer origins means fewer handshakes; preconnect the ones found late.
  10. Recap. URL → DNS → TCP → TLS → first byte → more origins → paint.

Sources

Play the lesson: URL to pixels