How do you update a file that is already cached on a CDN?
Either purge the URL on the CDN, which is slow and rate limited, or better, put a version or content hash in the filename, such as app.3f9a1c.js. A new name is a new cache entry, so there is nothing to invalidate.
Explain it simply
Suppose you cached app.js for a year and then fix a bug. Users' browsers and CDN edges still hold the old file. Two ways to deal with that.
Purge (invalidate): ask the CDN to delete the object from all edges. It works but takes time to propagate, may cost money, and does nothing for copies already in browsers.
Versioned URLs (cache busting): include a hash of the content in the filename. When the file changes, its name changes, so every cache treats it as a brand-new object. The old file simply stops being requested. Because the name is unique to its content, you can safely set a very long max-age and the immutable flag.
The HTML page that references the file should be cached briefly or not at all, so it always points to the latest filename. Build tools like webpack and Vite generate hashed names automatically.
Example
Before: <script src="/app.3f9a1c.js"> max-age=31536000, immutable
Fix bug, rebuild:
After : <script src="/app.b72e08.js"> new URL = new cache entry
index.html: Cache-Control: no-cache (checked every time)Returning users fetch the new HTML, see the new filename, and download the new script.
What to say in the interview
"I prefer content-hashed filenames with long cache lifetimes, and short cache on the HTML that references them. That makes updates instant without purges. I keep CDN purge for emergencies, like removing wrong or sensitive content."