Time to First Byte (TTFB)

Reducing server and network latency across DNS lookup, TCP/TLS negotiation, CDN edge routing, and origin response generation.

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

  1. Serve HTML at the CDN Edge: Host static sites on edge networks (GitHub Pages, Cloudflare Pages, Fastly, Netlify) or cache dynamic HTML with s-maxage and stale-while-revalidate so responses originate within ~20–50ms of the user.
  2. 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.
  3. 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.
  4. Use HTTP 103 Early Hints: Allow your edge proxy to send Link: </assets/css/style.css>; rel=preload; as=style while 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)
  });
}