Skip to content

Instantly share code, notes, and snippets.

@mcrumley
Created June 3, 2013 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcrumley/5700157 to your computer and use it in GitHub Desktop.
Save mcrumley/5700157 to your computer and use it in GitHub Desktop.
Gets a unique URL to avoid browser cache
function cache_buster(url) {
cache_buster.nonce = cache_buster.nonce || 1;
var sep = "?";
var qpos = url.indexOf("?");
if (url.length === 0 || qpos === url.length-1) {
sep = "";
} else if (qpos >= 0) {
sep = "&";
}
return url + sep + "nocache=" + (new Date()).getTime() + "-" + cache_buster.nonce++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment