i always append version numbers. then you just need to update the version variable:
var version = 1;
- var script = document.createElement("script");
- script.src = "justsomescript.js?v="+version;
You can also try the following:
var script = document.createElement("script");
script.src = "justsomescript.js?" + (new Date()).getTime();
Thanks for the suggestion. That works, but I generally dislike cache-defeating measures for assets that rarely change. I'd essentially be making my own life easier at the expense of the end-user experience once all these pages hit production.
I suppose I could tweak the generated query string so it only forces a refresh, like, every hour or so.
The version number idea might be better, in that you would only change that when you have made changes to the JS file.
This is a support script used by hundreds of pages, so modifying them all every time the script is updated isn't a practical option. For now I'll try rolling out something like this:
script.src = "test.js?" + Math.floor(new Date().getTime() / 3600000);
Essentially expiring the script once an hour, on the hour.
1 person found this helpful
i use an anchor function that updates all the pages versions. this is the jquery version:
var hrefA = $(this).attr('href').split('?v=');