Created
May 18, 2016 11:26
-
-
Save kucukharf/56a0f20c8889ce5d19a07ea0ffad1e3d to your computer and use it in GitHub Desktop.
Cache Buster Snippet
This file contains 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
(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