How to Reduce Time to First Byte (TTFB)

Time to First Byte (TTFB) is how long the browser waits for the first piece of a page after asking for it. Before changing settings, find out whether the delay comes from a redirect, your server, or the connection. A CDN cache can speed up public pages, but it can’t fix a slow server and must never share personalized pages.

Does a CDN cache make pages start loading sooner?

It can. A CDN can send the start of a public page sooner when it serves the page from a nearby cache. In one vendor test, slow responses got much faster and already-fast ones barely changed.

Moderate confidence. Good evidence, with some gaps. Based on 2 sources: 1 controlled test, 1 official doc.

What to do

Compare first-byte time for a cache hit and a cache miss from your visitors’ region. Cache public pages where it’s safe, and keep logged-in, checkout, and personalized pages out of the shared cache.

On this page
  1. What to do
  2. How to find what’s slowing down TTFB
  3. Which pages are safe to cache?
  4. Check the speed gain and look for stale pages
  5. The evidence
  6. Related tactics

How to find what’s slowing down TTFB

For the main page, TTFBTTFBTime to First Byte: how long the server takes to start sending a page after someone requests it. includes setting up the connection, any redirectsredirectAn instruction that sends visitors and search engines from an old address to a new one. A 301 means the move is permanent., and the time your server spends building the page. Open a slow public page in Chrome, then open DevTools and the Network tab to see each part.

A content delivery networkCDNContent delivery network: servers around the world that keep copies of your pages so visitors get them from somewhere close., or CDN, stores copies of your pages on servers around the world, closer to visitors. Cloudflare and Fastly are examples. When the CDN has a copy ready, that’s a cachecacheA saved copy of a page that can be sent to visitors quickly instead of building the page from scratch each time. hit. When it has to ask your server, that’s a miss. Most CDNs add a header that says which one happened, such as cf-cache-status on Cloudflare.

  1. In Chrome DevTools, open the Network tab, reload, and click the first request, which is the page itself. In Timing, note Waiting for server response. In Headers, note the status code, any Location header (a redirect), the cache status header, age and cache-control.
  2. Repeat from the same location after clearing the CDN cache, so you see a miss. Label each response as a hit, a miss, a redirect, or a response straight from your server.
  3. Fix the biggest wait. Remove extra redirects, speed up your server or database for slow misses, or cache public pages to get more hits. Then test from a second location.

Which pages are safe to cache?

Pages that look the same for every visitor. A public article or a product guide usually fits. Check that language, region, campaign links and login state still work correctly. Set a time limit on cached copies, and have a way to clear them when you update a page.

Never put account pages, checkout or anything personalized in a shared cache. After changing the rules, open those pages signed out and from two separate test accounts. Make sure one account can never see another account’s details.

If you serve different versions by language or region, make the language or region part of the cache key. The cache key is what the CDN uses to tell copies apart. Without it, a visitor in France could get the English copy.

Bottom line

Cache a page only if every visitor should see exactly the same thing. When in doubt, leave it out of the cache.

Check the speed gain and look for stale pages

Say repeated tests from one city show 600 ms for misses and 180 ms for hits. In this example, caching helps the people who get a hit. Check how often real visitors get hits, and whether the regions where most of your traffic comes from improve.

Publish a normal update and make sure the changed pages show the new content after you clear the cache. If misses are still slow, look at your server, such as slow database queries or redirects. If hits and misses are both fast but the page still feels slow, the problem comes after the first byte. Use a Performance trace to find it.

Bottom line

Before you turn on a new cache rule for everyone, publish a test edit and confirm visitors see the new version in each region.

The evidence

Cloudflare’s WordPress test found 90th-percentile first-byte time fell from 1,252 to 351 milliseconds. Its 10th-percentile time moved from 254 to 261 milliseconds. The gain depends on the starting setup and whether the HTML can be served from the cache.

  • Cloudflare · Controlled test · 2020

    Introducing Automatic Platform Optimization, starting with WordPress

    Across 505 tested sites, Cloudflare reported that 90th-percentile TTFB moved from 1,252 ms to 351 ms and 10th-percentile TTFB moved from 254 ms to 261 ms.

    Single WebPageTest location and a vendor-run test of a feature bundle. The result does not predict savings for a particular site or demonstrate a ranking effect.

  • web.dev · Official guidance · 2023

    Optimize Time to First Byte

    A cache hit can skip a trip to the origin. The guidance distinguishes hits from misses and recommends avoiding shared caching of personalized content.

    Distance, origin time, cache settings and cache-hit rate determine the benefit.

Every source above was checked against the original by a second reviewer. How we rate the evidence