How HTTP Works

Glossary Term

TTFB (Time to First Byte)

TTFB is the time from starting a request until the first byte of the response arrives. Learn what it includes, how to measure it and what usually inflates it.

Reviewed 2 min readintermediate3 sourcesMarkdown
On this page

TL;DR: TTFB is how long the browser waits until the first byte of the response shows up. For a page load it counts redirects, DNS, TCP, TLS and the server’s think time, not only your backend.

Time to First Byte (TTFB) is the time from the start of a request until the first byte of the response is received. In the Navigation Timing API, for a page load it is responseStart - startTime, so everything before the server starts replying is counted: redirects, DNS lookup, TCP and TLS setup, the request itself, and the server’s processing time.

Measuring it

curl -o /dev/null -s -w 'dns=%{time_namelookup} connect=%{time_connect} tls=%{time_appconnect} ttfb=%{time_starttransfer} total=%{time_total}\n' https://example.com/

time_starttransfer is the time to the first byte, measured from the start of the curl run. Subtract time_appconnect to get roughly the server’s wait. In the browser:

const [nav] = performance.getEntriesByType('navigation')
console.log('TTFB ms:', nav.responseStart)

Non-obvious facts

  • Two definitions in circulation. DevTools’ “Waiting for server response” is only the wait after the request is sent. Field data (CrUX, RUM, PageSpeed) counts from navigation start. Compare like with like before declaring a regression.
  • Redirects count. An http to https hop or a www redirect adds a full round trip, and sometimes a second TLS handshake, before the first byte of the real page.
  • Streaming changes what “first byte” means. A server that flushes headers or a shell early gets a low TTFB even if the body takes seconds. Low TTFB alone does not mean the page is fast.
  • You can see where the time went. Have the server emit a Server-Timing header (Server-Timing: db;dur=53, app;dur=47) and it appears in DevTools and in the Performance API.
  • Common inflators. A cold cache or cache bypass at the CDN, a slow database query, a serverless cold start, a distant origin, and a missing connection reuse to the upstream.

Go deeper

Frequently asked questions

What is TTFB?

Time to First Byte is the time between the start of a request and the arrival of the first byte of the response. For a page navigation it includes redirects, DNS, connection setup, TLS and the server wait.

What is a good TTFB?

web.dev suggests 0.8 seconds or less at the 75th percentile is good and more than 1.8 seconds is poor. It is a diagnostic metric, not one of the Core Web Vitals.

Why is the TTFB in DevTools smaller than in PageSpeed or RUM data?

The DevTools Network panel shows only the "Waiting for server response" phase. Field tools measure from navigation start, so they include redirects, DNS, TCP and TLS.

Does a CDN lower TTFB?

Yes for cacheable responses, because the edge answers without contacting the origin and the TLS connection is short. It does not help uncached dynamic responses that must reach a slow origin.

Sources

  1. web.dev: Time to First Byte (TTFB)web.dev
  2. MDN Web Docs: Time to first bytedeveloper.mozilla.org
  3. W3C Navigation Timing Level 2w3.org

Keep going

Browse /search