Skip to content

Instantly share code, notes, and snippets.

@kucukharf
Created May 18, 2016 11:26
Show Gist options
  • Save kucukharf/56a0f20c8889ce5d19a07ea0ffad1e3d to your computer and use it in GitHub Desktop.
Save kucukharf/56a0f20c8889ce5d19a07ea0ffad1e3d to your computer and use it in GitHub Desktop.
Cache Buster Snippet
(function (){
var rep = /.*\?.*/,
links = document.getElementsByTagName('link'),
scripts = document.getElementsByTagName('script'),
process_scripts = false;
for (var i=0;i<links.length;i++){
var link = links[i],
href = link.href,
operator = (rep.test(href)) ? '&' : '?';
link.href = href + operator + Date.now();
}
if(process_scripts){
for (var i=0;i<scripts.length;i++){
var script = scripts[i],
src = script.src,
operator = (rep.test(src)) ? '&' : '?';
script.src = src + operator + Date.now();
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment