Anatomy of TTFB
Time to First Byte (TTFB) measures the elapsed time between the browser requesting a resource and receiving the very first byte of the response:
TTFB = Redirect Time + Service Worker Startup + DNS Lookup + TCP/TLS Handshake + Request/Response Wait
Because neither First Contentful Paint (FCP) nor LCP can begin until HTML arrives, a high TTFB penalizes every downstream loading metric.
Optimization Strategies
- Serve HTML at the CDN Edge: Host static sites on edge networks (GitHub Pages, Cloudflare Pages, Fastly, Netlify) or cache dynamic HTML with
s-maxageandstale-while-revalidateso responses originate within ~20–50ms of the user. - Eliminate Redirect Chains: Avoid multi-hop redirects (
http://example.org→https://example.org→https://www.example.org/en/). Configure HSTS and direct canonical DNS routing. - Enable TLS 1.3 and HTTP/3 (QUIC): TLS 1.3 reduces handshake round-trips to 1-RTT (and 0-RTT on resumption), while HTTP/3 eliminates TCP head-of-line blocking on lossy mobile links.
- Use HTTP
103 Early Hints: Allow your edge proxy to sendLink: </assets/css/style.css>; rel=preload; as=stylewhile the origin server is still assembling dynamic HTML.
Inspecting TTFB Timing in the Browser
const [nav] = performance.getEntriesByType('navigation');
if (nav) {
console.log({
dnsMs: Math.round(nav.domainLookupEnd - nav.domainLookupStart),
tlsMs: Math.round(nav.connectEnd - nav.secureConnectionStart),
ttfbMs: Math.round(nav.responseStart - nav.requestStart)
});
}