patternjavascriptModerate
CDN Cache Layers and Purging
Viewed 0 times
cdn purgecache invalidationsurrogate keycache tagcloudfront invalidationfastly
Problem
After deploying updated content, the CDN continues to serve the old cached version to users for the duration of the TTL.
Solution
Use cache-busting filenames (content hashes in filenames) for static assets — they never need purging. For API/HTML responses, use CDN purge APIs on deploy. Use surrogate keys / cache tags to invalidate groups of responses atomically.
Why
Content-hashed filenames give you infinite TTL without stale-content risk. API purging on deploy ensures users get fresh HTML/data without waiting for TTL expiry.
Gotchas
- CDN purge APIs are eventually consistent — a purge request does not guarantee instant removal from all edge nodes.
- Purging by URL purges one URL. If the same content is served at multiple URLs, you must purge all of them or use cache tags.
- Some CDNs (Fastly, Cloudflare) support surrogate-key/cache-tag purging; others (basic CloudFront) only support path-based purges.
Revisions (0)
No revisions yet.