Skip to main content
Back to cloud
Caching6 min

S3, CloudFront, and caching notes

Cache keys, invalidations, immutable assets, browser caching defaults, and how to avoid stale docs after deploys.

Takeaway

Cache immutable assets aggressively, keep HTML and metadata easy to refresh, and invalidate only the paths that can actually go stale.

01

Separate assets from documents

Hashed JavaScript, CSS, and media can use long-lived cache headers. HTML, sitemap, robots, and metadata routes should be easier to refresh because they represent the current public surface.

02

Know the cache key

CloudFront cache behavior depends on path, query strings, headers, cookies, and compression settings. Write down what varies before debugging a stale response so the team does not invalidate blindly.

03

Invalidate with intent

A full distribution invalidation is simple but slow and noisy. Prefer targeted invalidations for changed HTML, sitemap, robots, and content pages, then smoke test with a cache-busting request if needed.