Skip to the indexed answers
Digital Marketing Index

usdigitalmarketingindex.com SEO

Why might Time to First Byte remain high despite using a CDN?

Because the CDN may not be caching the HTML. A content delivery network speeds up whatever it is allowed to store at its edge. A CDN can be caching images, stylesheets, and scripts while the page itself, the HTML document, is passed through to the origin server on every request, either because the origin’s headers forbid caching or because the CDN is configured to treat HTML as dynamic. Time to First Byte is measured on that HTML request. If each visit still waits for the origin to build the page, the CDN’s presence changes little. web.dev gives 0.8 seconds or less as a good TTFB (web.dev’s guide to TTFB), and the way to find out why a site misses it is to read the response headers.

Cache hits and misses

Request the HTML and look at what the CDN reports. The header names differ by provider. The response below is a generic illustration.

$ curl -sI https://www.example.com/guides/heat-pump-rebates/

HTTP/2 200
content-type: text/html; charset=utf-8
cache-control: private, no-cache
set-cookie: session=abc123; Path=/
age: 0
x-cache: MISS

What each line says:

Header Reading
cache-control: private, no-cache The origin is telling shared caches not to store this response
set-cookie A cookie is being set on a page view, which can lead a CDN to skip caching
age: 0 The response was just generated; it did not come from a cache
x-cache: MISS, or the provider's equivalent The edge did not have a stored copy

Run the same request for an image or stylesheet. If that shows a hit and a large age value while the HTML shows a miss, the CDN is working for static files and bypassing the page.

Measure the timing directly:

$ curl -s -o /dev/null -w "%{time_starttransfer}n" https://www.example.com/guides/heat-pump-rebates/

The number printed is the time, in seconds, until the first byte arrived. Run it several times. A cached page returns in a consistent, short time. An uncached one varies with origin load.

Dynamic response bypasses

Reasons a CDN does not cache HTML:

  • Origin headers: cache-control set to private, no-store, or no-cache, or a max-age of zero.
  • Cookies: a session or tracking cookie set on every response, or a rule that bypasses the cache when any cookie is present in the request.
  • Query strings: each distinct parameter combination treated as a separate cache entry, so tracked links never hit.
  • Vary headers: varying on a header with many values, such as the full user agent, which splits the cache into fragments.
  • Personalization: logged-in state, location, or experiments rendered into the HTML.
  • Default configuration: the CDN caches static file extensions only until told otherwise.
  • Short lifetimes: a time to live of seconds, so the entry has expired before the next visitor arrives.
  • Low traffic per edge location: a page requested rarely at a given location may not be in that location’s cache.

Origin latency

When the request does reach the origin, its own speed sets the floor. Look at:

  • Application time: database queries, API calls, and template rendering for the page.
  • Whether the origin has its own page cache.
  • Server capacity, and whether response time rises with traffic.
  • The distance between the CDN edge and the origin, and whether the connection between them is reused.
  • Redirects before the final response. Each one adds a round trip.

A server-timing header, if the application emits one, breaks the origin time into parts. Otherwise use application monitoring.

Measuring regional differences

A CDN’s benefit depends on where the visitor is. Test from several locations, since a result from one office says little about visitors elsewhere.

A proposed cache experiment, to establish whether caching the HTML would fix the problem:

  1. Choose one page type with no personalization, such as an article.
  2. Record the baseline: TTFB from three regions, five runs each, and the cache status header on each run.
  3. Change the origin’s response for that page type to allow shared caching for a short period, for example cache-control: public, s-maxage=300, and stop setting cookies on it.
  4. Configure the CDN to cache HTML for that path and to ignore tracking parameters in the cache key.
  5. Repeat the measurements. The first request in each region will be a miss. Later ones should be hits.
  6. Compare.

A table for recording it. The values shown are placeholders illustrating the layout.

Region Baseline TTFB, median Baseline cache status After, median After cache status
Near the origin 0.6 s MISS 0.1 s HIT
Another continent 1.4 s MISS 0.1 s HIT
A third region 1.1 s MISS 0.2 s HIT

If the after column shows hits and short times, uncached HTML was the cause. If the hits appear and TTFB is still high, look at the network path or at redirects. If the status stays at miss, the configuration is not taking effect, and the headers will show which rule is preventing it.

Before caching HTML more widely, check what must not be cached.

  • Pages that differ per user must be excluded, or the personal parts loaded separately after the cached shell.
  • A purge has to be triggered when content changes.
  • The cache key must not let one visitor’s version be served to another.

Confirm the improvement in field data afterward. TTFB is not itself one of the Core Web Vitals. It comes before them, and a slow first byte delays everything that follows, including the largest contentful paint.

Deciding in advance what a new site’s response times and page weights should be, before problems like this appear, is the purpose of a performance budget, covered in the guide to what a web performance budget should specify before a new site is built.

The first check is the simplest: request the HTML, read the cache status header, and see whether the page itself is being served from the edge.

Link trail

Reader comments on this answer

Add your comment to this answer

Your email address will not be published. Required fields are marked *