Video in progress
After updating the JS and CSS files on the CDN, users see the old version. How do you set this up properly?
Put a content hash in the file name (app.3f9a1c.js) and cache those files for a long time; serve the HTML for a short time or with revalidation. A new deploy means a new name, so no invalidation is needed.
📖 Answer
The problem: app.js sits on the CDN and in browsers with max-age=86400. A new version was deployed, but the name is the same — nobody requests the new file. Even if you purge on the CDN, the browser cache remains. Worse still: the new HTML loads with the old JS or vice versa, and the page breaks.
The right scheme:
# app.3f9a1c.js, style.8be21d.css — the name changes when the content changes
Cache-Control: public, max-age=31536000, immutable
# index.html — checked every time
Cache-Control: no-cache
ETag: "v-2026-11-03-1"
no-cache doesn't mean "don't cache" — it means "check with the server before using it". If the ETag matches, a 304 comes back and there's almost no traffic.
Spring Boot has this ready-made:
spring:
web:
resources:
chain:
strategy:
content:
enabled: true
paths: /**
cache:
cachecontrol:
max-age: 365d
Thymeleaf turns @{/js/app.js} into the hashed name automatically.
The deploy order matters: first the new assets are uploaded, then the HTML that references them. Don't delete the old assets for a few days — users who still have the old HTML open will keep requesting them.
There are cases where you still need a purge (a wrong image, a legal request). Do it through the CDN API, but don't make it a routine deploy step — a purge is slow and takes time to propagate globally.
Sign up to mark studied questions and save your progress.