When a page feels slow, the instinct is to optimize code. More often the delay is physical: the request travelled thousands of kilometres to an origin server, waited for a database, and travelled back. Caching and edge delivery attack that directly.
Start by measuring the right thing
Time to First Byte is the number to watch. Anything above roughly 800ms means your problem is upstream of the browser, and image optimization will not help. Split TTFB into its parts: connection and TLS handshake, queueing, and response generation. Slow handshakes point at distance; slow generation points at your database or code.
The strategies, from cheapest to most involved
- Fully static. Pages built at deploy time and served as files. Unbeatable latency, but every content change needs a rebuild.
- Incremental regeneration. Static pages with a revalidation window. The first visitor after expiry triggers a rebuild in the background while everyone else keeps getting the cached version. This is the sweet spot for most content sites.
- Stale-while-revalidate. The same idea expressed at the HTTP layer with
Cache-Control: s-maxage=60, stale-while-revalidate=600. Simple, works with any CDN, and gives you a warm cache almost all the time. - Edge rendering. The page is generated at a node near the user. Useful when the response must be personalized but cheap to compute. Remember that if the edge function still calls a single-region database, you moved the compute but not the distance.
- Origin rendering with a CDN in front. The traditional setup, still fine if you cache aggressively and purge precisely.

Pick per route, not per project
The mistake is choosing one rendering strategy for a whole application. A realistic blog looks like this: the article pages are static with a long revalidation window; the index is incrementally regenerated every few minutes; search is rendered on demand; the account page is never cached. Mixing is not complexity, it is precision.
Cache keys and the personalization trap
The fastest way to destroy a cache is to vary on something high-cardinality. Vary on cookies and you have a cache of one entry per user. If a page differs only by a small fragment — a name in the header, a cart count — cache the page and fetch the fragment separately on the client. That one pattern turns a 0% hit rate into a 95% hit rate.
Invalidation that you can trust
Two rules keep this manageable. First, give static assets immutable filenames with hashes and a one-year cache lifetime, so they never need purging. Second, for HTML prefer short TTLs with stale-while-revalidate over long TTLs plus manual purges — purging is where cache bugs live. When you do need targeted purges, tag responses by content type so one edit clears exactly the pages it affects.
A quick audit
- Load a popular page twice and compare TTFB. No improvement means you are not caching HTML at all.
- Check the cache status header your CDN returns. A high MISS rate usually means a bad cache key.
- Look for
Set-Cookieon cacheable responses — many CDNs refuse to cache those. - Confirm compression and HTTP/2 or HTTP/3 are enabled end to end.


