I have an old version of a JS file cached on users’ browsers, with expiration set to 10 years (since then, I have learned how to set expires headers correctly on my web server). I have made updates to the JS file, and I want my users to benefit from them.
- Is there any way my web server can force users’ browsers to clear the cache for this one file, short of serving a differently named JS file?
- In the future, if expires headers are not set correctly (paranoia), can my JS file automatically expire itself and force a reload after, say, a day has passed since it was cached?
EDIT: Ideally I want to solve this problem without changing HTML markup on the page that hosts the script.
In short… no.
You can add something to the end of the source address of the script tag. Browsers will treat this as a different file to the one they have currently cached.
Not sure about your other options.