Before the request leaves: URL, caches, DNS, TCP and TLS
You type shop.example/orders and press Enter. Before any byte goes to shop.example, the browser works through these steps:
- Is it a URL or a search?
shop.example/orderslooks like a host and a path, so it becomeshttps://shop.example/orders(modern browsers try HTTPS first).best running shoeswould go to the search engine instead. - HSTS. If
shop.exampleis on the browser’s HSTS list (from an earlier visit or the built-in preload list),http://is rewritten tohttps://without asking the network. - Caches. If a service worker is installed for the site, it gets the request first and may answer from its own cache, even offline. Otherwise the browser’s HTTP cache may hold a fresh copy of the page. Either way, no network at all.
- DNS. The browser needs an IP address for
shop.example. It checks its own cache, then asks the operating system, which asks the configured resolver (at home, the router or the provider; often an encrypted DNS service). The answer is cached for its TTL. See DNS. - TCP connection. The browser connects to the IP on port 443: SYN, SYN-ACK, ACK, one round trip. See TCP vs UDP.
- TLS handshake. The browser sends the hostname and its key share, the server answers with its certificate, and both derive keys: one more round trip with TLS 1.3. The browser verifies the certificate chain. See TLS and HTTPS.
- The HTTP request goes out, encrypted:
GET /orders, with headers likeHost,Accept,Accept-Encoding,CookieandUser-Agent. If the server supports HTTP/2, it was agreed during the TLS handshake; if it advertised HTTP/3, the browser may use QUIC over UDP, which merges steps 5 and 6.
If the browser already has an open connection to shop.example from a moment ago, steps 4 to 6 are skipped entirely: the request goes out on the existing connection.
- Input handling: omnibox heuristics (search vs navigation), IDN to Punycode with spoofing checks, HTTPS-first upgrades (Chrome’s HTTPS-Upgrades fall back to HTTP if HTTPS fails), HSTS (dynamic and preloaded), and the browser’s own speculative work: DNS prefetch and preconnect while you type, prerendering of likely URLs.
- Before the network:
beforeunloadof the current page, the back/forward cache for history navigations, service workerfetchhandlers (navigation preload lets the network request start in parallel with worker boot), the HTTP cache (HTML is usuallyno-cache, so a conditional request). - DNS: browser cache, OS cache (mDNSResponder on macOS, systemd-resolved on Linux),
hostsfile, DoH or DoT to the resolver if configured, then recursive resolution. The browser may also queryHTTPSrecords to learn about HTTP/3 and ECH before connecting, and races IPv6 against IPv4 (Happy Eyeballs). - Connection: TCP plus TLS 1.3 is 2 RTT before the request (1 RTT with TCP Fast Open, rarely used); QUIC is 1 RTT, or 0 with 0-RTT resumption (replayable, so only safe requests). Connection pooling and HTTP/2 coalescing (one connection for several hostnames on the same IP and certificate) avoid new handshakes.
- Request: HTTP/2 or HTTP/3 with HPACK or QPACK header compression;
Sec-Fetch-*headers describe the request’s context; cookies by SameSite rules;Accept-Encoding: gzip, deflate, br, zstd. - Measuring: Navigation Timing in the browser (
domainLookupStart,connectEnd,secureConnectionStart,responseStart),curl -won the command line, and real-user monitoring for what users actually experience.
Predict the output
curl fetched https://www.wikipedia.org/ twice from a laptop and printed the cumulative times below (seconds since the start). Roughly how long did the TLS handshake take on the first run?
curl -s -o /dev/null -w 'dns %{time_namelookup} tcp %{time_connect} tls %{time_appconnect} ttfb %{time_starttransfer} total %{time_total}\n' https://www.wikipedia.org/
# dns 0.012366 tcp 0.051183 tls 0.101307 ttfb 0.152796 total 0.244031
# dns 0.004432 tcp 0.041765 tls 0.087966 ttfb 0.136843 total 0.233632curl's timings are cumulative: DNS finished at 12 ms, TCP connected at 51 ms (one round trip of roughly 40 ms after DNS), TLS was done at 101 ms (one more round trip of about 50 ms, TLS 1.3), the first byte of the response arrived at 153 ms, and the whole page at 244 ms. On the second run DNS was cached by the operating system (4 ms). Two of the four steps before the first byte are pure handshakes, which is why connection reuse and nearby servers matter so much.
# 1. DNS: which addresses, and how long they may be cached
dig +noall +answer shop.example A shop.example AAAA
# 2-3. TCP and TLS: the negotiated protocol and certificate
echo | openssl s_client -connect shop.example:443 -servername shop.example -alpn h2,http/1.1 2>/dev/null \
| grep -E 'ALPN|Protocol|Verify return'
# 4. HTTP: the request and response headers curl sends and receives
curl -sv -o /dev/null https://shop.example/orders 2>&1 | grep -E '^[<>*] '
# all of it with timings
curl -s -o /dev/null -w 'dns %{time_namelookup} tcp %{time_connect} tls %{time_appconnect} ttfb %{time_starttransfer}\n' https://shop.example/// in the browser console: the same phases for the current page
const [nav] = performance.getEntriesByType('navigation');
console.table({
dns: nav.domainLookupEnd - nav.domainLookupStart,
tcp: nav.secureConnectionStart - nav.connectStart,
tls: nav.connectEnd - nav.secureConnectionStart,
waitingForServer: nav.responseStart - nav.requestStart,
download: nav.responseEnd - nav.responseStart,
});Worked example: the first visit from a phone
- Input. On a phone in Belgrade, the user taps a link to
https://shop.example/orders. No HSTS entry yet, but the URL is already HTTPS. - No cache. First visit: no service worker, nothing in the HTTP cache.
- DNS, 30 ms. The phone’s resolver doesn’t have the name cached, so it asks the root,
.exampleand the shop’s name servers. Answer: an IP of the CDN’s server in Frankfurt, TTL 300 seconds. - TCP, 25 ms. One round trip to Frankfurt over mobile data.
- TLS, 25 ms. One more round trip; the certificate for
shop.examplechecks out. HTTP/2 is agreed during the handshake. - Request and wait, 120 ms. The CDN doesn’t have the page (HTML is personal), so it forwards the request to the shop’s servers in Ireland and waits for the answer.
- First byte at about 200 ms. The HTML starts arriving. On the next tap, DNS and both handshakes are already done, and only step 6 remains.
Deep diveMaking the first connection fasterInterview favorite
“Our landing page’s time to first byte is 600 ms on mobile. Where would you look?” Split the time into phases (Navigation Timing or RUM data by country and network type) and attack the biggest:
- DNS: long-TTL records for stable endpoints, a fast authoritative provider with anycast, fewer distinct hostnames on the critical path (each third-party domain is another lookup and handshake),
dns-prefetchfor unavoidable ones. - Distance: every round trip is paid two or three times before the first byte. A CDN or edge terminating TLS near the user cuts each one from 150 ms to 20 ms, even when the HTML itself comes from a distant origin (the edge keeps warm connections to it).
- Handshakes: TLS 1.3 everywhere, session resumption, HTTP/3 advertised through
Alt-Svcand DNSHTTPSrecords, OCSP stapling no longer needed with short-lived certificates, a lean certificate chain (ECDSA, no extra intermediates) so the handshake fits in the first flight. - Connection reuse: one origin for the page and its API (no extra handshake, no CORS preflight), HTTP/2 coalescing,
preconnectfor the second origin you can’t avoid. - Server time: the waiting phase is the application. Cache rendered HTML at the edge for anonymous users, stream the HTML head early, and send 103 Early Hints so the browser starts fetching CSS while the server is still thinking.
- Redirects:
http://tohttps://towww.to/en/is three extra round trips, each possibly with new DNS and handshakes. Collapse them into one, or none with HSTS preload.
Say how you’d verify: before and after RUM percentiles (p75 and p95, not averages) per region and connection type.
- Browser: omnibox, IDN, HTTPS-first and HSTS, bfcache, service worker (navigation preload), HTTP cache; speculative preconnect and prerender.
- DNS: browser → OS → resolver (DoH/DoT) → recursion;
HTTPSrecords for h3 and ECH; Happy Eyeballs. - TCP + TLS 1.3 = 2 RTT before the request; QUIC 1 RTT (0-RTT for safe requests); reuse and coalescing skip it.
- First-byte tuning: edge termination, fewer hostnames and redirects, resumption, HTTP/3, 103 Early Hints; measure with Navigation Timing and RUM percentiles.
curl -s -o /dev/null -w 'dns %{time_namelookup} tcp %{time_connect} tls %{time_appconnect} ttfb %{time_starttransfer}\n' https://host/Check this part
The browser already has an open connection to shop.example. Which steps does the next request skip?
What can answer a request before it reaches the network at all?
How many round trips before the HTTP request for a new TCP plus TLS 1.3 connection, and for a new QUIC connection?
Which change cuts first-byte time most for distant mobile users?