
A browser can't paint anything until the first byte of the page arrives. For a visitor far from your server, a large share of that wait comes from distance, and no amount of code tuning will remove it. A CDN can, if it's pointed at the right part of the problem. This post shows how to reduce TTFB step by step, starting with a measurement you can run in one minute.
Where does time to first byte come from?
People blame "a slow server" and start optimising queries, then find the number barely moves. Wikipedia's article on time to first byte (TTFB) explains why: the measurement covers the socket connection time, the time to send the request and the time to receive the first byte, and it always includes network latency.
Say your origin is in Frankfurt and a visitor sits in Singapore, about 10,300 km away. Light in optical fibre covers roughly 200,000 km/s, so one way takes 10,300 / 200,000 = 0.0515 s, or 51.5 ms. A round trip is therefore at least 103 ms, and real routes are longer. A first request over HTTPS on a fresh connection needs one round trip for the TCP handshake, one for the TLS 1.3 handshake and one for the request itself: 3 x 103 ms = 309 ms before the server has done any work. Put a server 10 ms away and the same three round trips cost 30 ms.
NetDNA's product page states a response time under 25 ms from most of its locations. Whatever your provider's figure is, the sums above show why distance is the first thing to remove.
To see your own split, curl can print each stage:
curl -o /dev/null -s -w 'connect %{time_connect} tls %{time_appconnect} ttfb %{time_starttransfer}\n' https://www.example.com/
Subtract connect from tls to get the TLS handshake, and tls from ttfb to get request time plus server thinking time. If the first two are large, distance is the problem. If the last is large, the server is.
Which part can a CDN actually remove?
Many teams put images on the CDN and leave the HTML on the origin, so the slowest request of the page, the first one, stays slow. Three changes address it.
- Connections that end near the visitor. Even for an HTML page the edge can't cache, the visitor's TCP and TLS handshakes finish at a nearby server. In the Singapore example that turns 2 x 103 ms of handshakes into 2 x 10 ms. The edge then reuses a warm connection to the origin.
- Short caching of anonymous HTML. Say a news page gets 20 requests a minute and you allow a 60-second shared-cache lifetime (
Cache-Control: public, s-maxage=60). One request per minute reaches the origin and 19 of 20 are served from the edge: a 95% hit rate for a page that's never more than a minute old. The Cache-Control guide shows the headers, and EdgeRules can set the lifetime at the edge when the origin can't change its headers. - Long lifetimes for static assets. Fingerprinted CSS, JavaScript and images can live a year, so they never trigger an origin trip.
The reason this works is arithmetic, not magic: each change removes round trips to a far-away machine, and round trips are what make up most of the 309 ms.
What about the server's own thinking time?
An edge can't speed up a page that takes 1.2 seconds to build. When a request misses the cache, the origin still does the full job. Wikipedia's TTFB entry makes the same point: static pages show a very low TTFB, while larger dynamic responses pulled from a database run higher.
Take a WordPress page that needs 1.2 s to generate with a 95% edge hit rate. The average wait looks fine: 5% x 1.2 s = 60 ms. But the average hides the fact that one visitor in 20 still waits the full 1.2 s, and those are the ones who bounce. Watching the 95th percentile instead of the mean exposes them.
The fix sits at the origin: a page cache, fewer database queries per request, and, where it's offered, an origin shield so a burst of misses from several locations collapses into one origin request. Compression at the origin matters too; compressing on the fly at a high level delays the first byte, which is why precompressed files are the better pattern.
Personalised pages need a bypass, not a guess
Caching HTML is risky if the page differs per visitor. A logged-in dashboard cached for 60 seconds would show one person's data to another. The safe rule is to cache only responses with no session cookie and no personalised content, and to let everything else bypass the cache. Setting Cache-Control: private on those pages tells shared caches to stay out.
A first-byte budget worth writing down
Setting numbers per page type makes regressions visible. A reasonable starting budget (ours, not an official limit): cached HTML under 200 ms from your main markets, uncached HTML under 800 ms, and static assets under 100 ms. Run the curl command above from two or three regions once a month and note the three numbers. When one jumps, the split between connect, TLS and server time tells you where to look first.
Related: CDN slowness and bad performance, the NetDNA network, glossary: PoP and Anycast.
Blog