~learn.
0:00 / 1:09
W00 · Foundations

You cached app.js for a year. Then you shipped a bug fix.

transcript

You ship a bug fix to app dot js. Your users keep running the old file. It's cached for a year.

Blame one header. Public: the CDN and the browser may keep it. Max age: one year. Immutable: don't even check for updates.

Purge it? A CDN can be purged. But the copy in each browser? You can't reach it. Cache it for 60 seconds instead? It works. But it throws away your hit ratio.

The real fix: put a hash of the file's content in its name. Change the code, and the hash changes. So does the URL. A new URL is an automatic cache miss. Everyone gets the fix straight away.

The old file just sits there until it expires. Harmless. Rollbacks are safe. And you never call a purge API.

Cache static files for a year, and never change one in place. New content gets a new name. That's the whole trick.

Full breakdown in the lecture.