Core Web Vitals (Part 8): TTFB, Caching and CDN Architecture
Improve the delivery layer behind Core Web Vitals: redirects, DNS/TLS, server work, edge caching, Cache-Control, immutable assets, stale-while-revalidate, compression and cache observability.

You cannot frontend-optimise time that disappeared before the HTML arrived.
If a request spends 1.4 seconds traversing redirects, reaching an origin, waiting for a database query and rendering a template, the browser begins every subsequent task late: discovering the LCP image, downloading CSS, requesting fonts and executing scripts.
This is why Time to First Byte (TTFB), caching and CDN architecture matter to Core Web Vitals even though TTFB itself is not one of the three Core Web Vitals.
A faster document response gives LCP more room. Efficient caching reduces repeat costs. Good edge delivery prevents every visitor on another continent from making a round trip to one origin server.
But caching is also one of the easiest places to serve the wrong user’s data or keep a broken release alive for hours. Performance and correctness have to be designed together.
TTFB is a sum of several things
The browser experiences “waiting for the document”, but the delay can include:
- redirects;
- DNS lookup;
- connection/TLS establishment;
- network distance;
- CDN/edge processing;
- cache lookup/miss;
- origin connection;
- application middleware;
- authentication/session work;
- API/database calls;
- server rendering;
- queue/load pressure.
If TTFB is poor, do not immediately scale the web server. Find the phase.
Remove redirect chains
A normal HTTP-to-HTTPS or canonical-host redirect may be unavoidable for mistyped/old URLs.
A chain is avoidable:
http://example.com
-> https://example.com
-> https://www.example.com
-> https://www.example.com/en/
Every hop adds request/response latency before the final document can begin.
Link internally to the final canonical URL and collapse server redirect logic where possible.
Migrations may require redirects for SEO/user continuity; that does not mean they should become permanent internal navigation architecture.
Put cacheable content near users
A CDN can terminate requests at geographically distributed edge locations and serve cached content without returning to the origin every time.
This is especially effective for:
- hashed JS/CSS assets;
- images/fonts;
- public static HTML;
- documentation/articles;
- public API responses with safe caching semantics.
Dynamic personalised pages need a more careful strategy.
Do not cache a user’s account page publicly because “edge caching improves TTFB”.
Understand browser cache versus shared cache
HTTP caching directives can apply differently to:
- the user’s browser/private cache;
- shared intermediary/CDN caches.
For example:
Cache-Control: public, max-age=300, s-maxage=3600
can allow a browser to consider the response fresh for five minutes while a shared cache can retain it for an hour.
Whether that policy is correct depends entirely on the resource.
Do not cargo-cult cache headers from a blog onto authenticated responses.
Hashed static assets should be aggressively cacheable
If your build emits:
app.8f31a7c2.js
styles.a21e019f.css
and the filename changes whenever content changes, those resources can usually use long-lived immutable caching:
Cache-Control: public, max-age=31536000, immutable
The release references a new URL when the asset changes, so clients do not need to constantly revalidate the old one.
This is one of the cleanest caching patterns on the web.
The corresponding HTML should generally not be cached for a year, because it is the document that points to the current asset hashes.
HTML caching needs a deployment strategy
Public HTML can often be cached, but decide how updates propagate.
Options include:
- short TTLs;
- explicit CDN purge/invalidation on deploy;
- versioned paths;
- stale-while-revalidate patterns;
- framework/platform incremental regeneration.
The right choice depends on how quickly content must change and how expensive origin rendering is.
If your pricing page can remain stale for five minutes, that is different from an incident-status page.
Make freshness a product requirement, not an accidental cache setting.
stale-while-revalidate can improve consistency of latency
Example:
Cache-Control: public, max-age=60, stale-while-revalidate=300
After the response becomes stale, supporting caches may be allowed to serve the stale response while revalidating it in the background for a further window.
That can avoid making a user wait for origin regeneration on every expiry boundary.
But stale content is still stale content. Do not use it where serving old data has unacceptable consequences.
stale-if-error can improve resilience
For suitable public content, allowing a cache to serve stale content when the origin is temporarily failing can turn an outage into slightly outdated content rather than an error page.
Again, context matters. Serving yesterday’s marketing article is very different from serving stale account balances.
Performance techniques are not permission to ignore data semantics.
Compression: Brotli and gzip are table stakes for text assets
HTML, CSS, JavaScript, JSON and SVG compress well.
Ensure your server/CDN negotiates appropriate content encoding. Brotli is commonly effective for HTTPS text delivery, with gzip as a widely compatible fallback.
Do not compress already compressed media such as JPEG/AVIF/video again expecting meaningful gains.
Also watch dynamic compression CPU cost at the origin. Precompressing static build assets or letting a capable CDN handle compression can be more efficient.
CDN does not fix a slow origin on cache misses
A CDN is not a force field around bad backend architecture.
If a response cannot be cached and every request still reaches an origin that spends 900 ms on sequential database/API calls, users still pay that cost.
Profile the backend:
- database query duration/count;
- N+1 calls;
- downstream APIs;
- template rendering;
- synchronously fetched configuration;
- authentication/session stores;
- cold starts;
- connection pool exhaustion.
Optimise the work or redesign the dependency chain.
Parallelise independent backend dependencies
Suppose server rendering needs profile, recommendations and feature configuration.
Bad conceptual flow:
await profile
await recommendations
await flags
render
If those operations are independent, sequential waiting increases TTFB unnecessarily.
Parallel execution may reduce wall-clock latency:
await all(profile, recommendations, flags)
render
But do not blindly parallelise everything against a database with limited capacity. Latency and load interact. Measure under realistic concurrency.
Do not make above-the-fold HTML wait for below-the-fold data
A server-rendered product page may block the whole document while fetching reviews, related products and footer recommendations.
If your architecture supports streaming or deferred sections, the critical content can often arrive earlier while secondary content follows.
The key question is: what information must exist before the browser can render the useful first screen?
Do not put unrelated dependencies in front of it.
Connection hints: useful, selective, easy to overdo
If a critical resource must come from another origin, preconnect can establish the connection earlier:
<link rel="preconnect" href="https://cdn.example.com" crossorigin>
This can save DNS/TCP/TLS setup later.
But connections consume resources. Preconnecting to ten advertising/analytics domains “just in case” can create unnecessary work.
Use hints for origins that are both important and likely to be needed promptly.
dns-prefetch is a lighter hint where early DNS resolution alone is useful.
HTTP/2 and HTTP/3 do not eliminate prioritisation
Modern protocols improve connection utilisation and reduce some historical reasons for domain sharding/concatenation.
They do not make request count, bytes or server work irrelevant.
A page that requests 250 unnecessary resources over HTTP/3 is still requesting 250 unnecessary resources.
Likewise, splitting assets across many hostnames can lose connection reuse and add DNS/TLS setup.
Design for the current protocol stack, not HTTP/1-era folklore.
Cache keys can quietly destroy hit rates
A CDN may vary cached responses by query strings, cookies, headers or other dimensions.
If every request includes a unique tracking parameter and your cache key includes the full query string, apparently cacheable pages can become misses.
Likewise, varying by unnecessary cookies can fragment the cache.
Inspect cache keys and hit ratios.
Only vary on inputs that actually change the response.
Be extremely careful when removing cookies/headers from cache keys: if a value changes personalised content, ignoring it can leak data between users.
Observe cache behaviour explicitly
Do not assume the CDN is caching because you configured a CDN.
Track:
- cache hit/miss/bypass;
- edge TTFB;
- origin TTFB;
- hit ratio by route;
- object age;
- purge behaviour;
- regional latency;
- origin request volume;
- response size/compression.
Expose diagnostic headers where appropriate in non-sensitive environments, for example:
X-Cache: HIT
Age: 142
The exact headers vary by provider.
A cache with a 5% hit rate is not delivering the architecture you think it is.
Service workers are another cache layer — treat them with respect
A service worker can provide powerful offline/runtime caching, but it can also keep old assets alive, create confusing update behaviour and make debugging much harder.
Use explicit strategies per resource type:
- cache-first for versioned static assets;
- network-first where freshness matters;
- stale-while-revalidate for appropriate content.
Do not cache every GET request forever.
And test upgrades. A service worker bug can persist on client devices after you have fixed the server.
Server timing helps connect frontend and backend traces
The Server-Timing response header can expose useful backend timing information to browser tooling:
Server-Timing: db;dur=42, render;dur=18, api;dur=73
This can make a slow TTFB investigation much faster because frontend engineers can see whether the delay came from database, rendering or another dependency.
Do not expose sensitive internal detail indiscriminately, but use observability to bridge the browser/server boundary.
Common delivery mistakes
Caching HTML and static assets identically
Their invalidation models are different.
Setting no-cache and assuming it means “do not store”
HTTP caching terminology is nuanced: no-cache generally requires revalidation before reuse; no-store is the directive that tells caches not to store the response. Choose deliberately.
Adding a CDN without measuring hit rate
A pass-through CDN may add little value.
Caching authenticated content publicly
Never trade data isolation for a faster benchmark.
Preconnecting to every third party
Connection setup is not free.
Solving origin latency only with more servers
If the application performs wasteful sequential work, horizontal scaling may improve capacity without fixing per-request latency.
Headers reveal a lot about delivery
Use SiteTidy to inspect your site's HTTP and delivery configuration, then combine it with CDN/origin telemetry to see whether your caching strategy is actually working.
Production checklist
- remove avoidable redirect chains;
- measure TTFB by geography and route;
- serve cacheable static assets from edge locations;
- use content hashes and long immutable caching for versioned assets;
- define HTML freshness/invalidation explicitly;
- use
stale-while-revalidateonly where stale content is acceptable; - compress text responses appropriately;
- profile backend dependencies on cache misses;
- parallelise independent server work where capacity allows;
- do not block critical HTML on secondary data;
- use connection hints selectively;
- inspect CDN cache keys and hit ratios;
- keep personalised responses isolated;
- observe origin versus edge timing;
- use service-worker caching deliberately;
- verify delivery changes against field LCP, not TTFB alone.
The fastest frontend is still slow if it spends the first second waiting for permission to begin.
Part 9 returns to the browser with a 2026-specific problem: measuring and optimising SPAs now that Chrome’s soft-navigation Core Web Vitals support is beginning to change what we can observe.
