Reload Page With TimeStamp Parameter Added to URL to Prevent Cached Versions From Being Loaded
Below is a function I use to reload an html page every time it is visited which appends a timestamp as a "version" parameter to the URL ensuring that it is never a cached copy of the page being retrieved.
// reloads page with a time-stamp appended to URL
// to ensure current form version loads
( function() {
var x = new Date().valueOf();
var now = x.toString().slice(-10);
var later = (x + 30000).toString().slice(-10);
var uSplit = window.location.href.toString().split('?');
if(uSplit.length > 1){
var oldNum = uSplit[1].slice(2);
var oldDate = parseInt(x.toString().replace(now, oldNum));
var diff = oldNum - now;
} else {
var diff = 0;
}
if(diff <= 0){
var newURL = uSplit[0] + "?v=" + later;
window.location.replace(newURL);
} else {
return false;
}
return false;
}());
This method adds a parameter to the URL, but it doesn't "change" it. It is the same method often used to carry over data from a form by adding the form data parameters to the end of the url.
Prevent Cached External .js Files
To ensure you are serving up-to-date javascript, that is included via script tags, from external .js files, you can use the jQuery getScript() function, which you can read about HERE. It adds a timestamp parameter to the end of the resource URL (not the actual page's URL), so that your external .js files being loaded are always current.
Example Usages:
$.getScript('url_to_your_javascript_file.js');