Skip to content

How it works

The browser records the timestamp at the start of the navigation and subtracts it from the timestamp of the first byte received; the difference is TTFB.

In the browser, TTFB is measured through the Navigation Timing API. The performance.timing object (or the modern PerformanceNavigationTiming interface) exposes navigationStart (when the user initiated the navigation), requestStart (when the first byte of the request was sent), responseStart (when the first byte of the response arrived), and a dozen intermediate timestamps. TTFB is computed as responseStart - navigationStart. That single number hides the fact that responseStart is defined as "the first byte received", so it includes DNS, TCP, TLS, and the origin's time-to-first-byte in the response stream.

sequenceDiagram
  participant B as Browser
  participant DNS as DNS server
  participant S as Server
  B->>DNS: Resolve hostname
  DNS-->>B: IP address
  B->>S: TCP SYN
  S-->>B: SYN-ACK
  B->>S: ACK + TLS ClientHello
  S-->>B: TLS ServerHello
  B->>S: HTTP request
  S-->>B: 200 OK + first byte (TTFB timestamp)

Server-side and synthetic measurements tell a complementary story. Synthetic tools (WebPageTest, Lighthouse, Pingdom) simulate a request from a chosen location with a chosen connection profile and report TTFB as a single number, together with a waterfall that breaks it into the phases above. Real-user monitoring (RUM) tools (Google Analytics, Chrome UX Report, Datadog RUM) aggregate TTFB across real visitors, grouped by country, network type, and device. The two disagree by nature: synthetic measures a specific, controlled request; RUM measures what users actually experience. Both are needed to diagnose TTFB problems correctly.

Reducing TTFB in production

  1. Diagnose before optimizing

    Break TTFB into its phases (DNS, TCP, TLS, request queue, server processing, response) before changing anything. Each phase has a different owner and a different fix.

  2. Move the server closer to the user

    A CDN edge cuts network round-trips for TCP, TLS, and content delivery. If the origin is in one region, users in other regions pay the intercontinental latency on every cold connection.

  3. Increase cache hit rate

    A cache hit at the edge responds in single-digit milliseconds; a cache miss forwards to the origin. TTFB is dominated by hit rate, not by origin speed.

  4. Reduce origin processing time

    Measure server response time (the gap between request received and first byte sent) separately. Reduce it with database indexes, query caching, template caching, and removing synchronous work from the request path.

Dynamic pages have a structural problem with TTFB: the origin must compute something before it can send the first byte. Static pages can be served from a cache with no computation. That is why CDNs (and static site generators, and edge caching of API responses) have such outsized effects on TTFB — they convert a "compute then respond" path into a "serve from cache" path. For dynamic pages that cannot be fully cached, the pattern is partial caching: cache the shell, revalidate the fragments, and stream the response.