HTTP caching reduces latency, server load, and infrastructure costs by storing responses at multiple layers—browsers, CDNs, proxies, and application caches. The guide explains how Cache-Control directives (max-age, s-maxage, no-cache, no-store, stale-while-revalidate), validators (ETag, Last-Modified), and headers like Vary control freshness and revalidation. It covers common misconceptions (no-cache doesn't mean "don't cache"), freshness calculations, practical recipes for static assets, HTML, APIs, and authenticated content, plus browser behaviors like BFCache and speculation rules. A detailed Cloudflare section addresses CDN-specific defaults, edge cache TTLs, cache key normalization, and cache tags for event-driven purging.

47m read timeFrom jonoalderson.com
Post cover image
Table of contents
Table of contentsThe business case for cachingMental model: who caches what?Cache keys and variantsFreshness vs validationCore HTTP caching headersFreshness & age calculationsCommon misconceptions & gotchasPatterns & recipesBeyond headers: browser behavioursCDNs in practice: CloudflareOther caching layers in the stackDebugging & verificationCaching in the AI-mediated webWrapping up: caching as strategy
3 Comments

Sort: