Created
February 14, 2018 13:39
-
-
Save xstable/a722b83a5db30390e8edd240b40c1f51 to your computer and use it in GitHub Desktop.
cacheBUSTER
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Cache Buster | |
// https://bgrins.github.io/devtools-snippets/#cachebuster | |
// Overwrite all link and (optionally) script tags by adding Date.now() at the end of href and src attributes, respectively. | |
// By default processing scripts is not performed, you should change the variable process_scripts to true to run these. | |
(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; | |
if(rep.test(href)){ | |
link.href = href+'&'+Date.now(); | |
} | |
else{ | |
link.href = href+'?'+Date.now(); | |
} | |
} | |
if(process_scripts){ | |
for (var i=0;i<scripts.length;i++){ | |
var script = scripts[i], | |
src = script.src; | |
if(rep.test(src)){ | |
script.src = src+'&'+Date.now(); | |
} | |
else{ | |
script.src = src+'?'+Date.now(); | |
} | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment