Skip to content

Instantly share code, notes, and snippets.

@muhibbudins
Created September 4, 2017 01:34
Show Gist options
  • Save muhibbudins/23056e6826f5ad3ba1928c8a498dd2b9 to your computer and use it in GitHub Desktop.
Save muhibbudins/23056e6826f5ad3ba1928c8a498dd2b9 to your computer and use it in GitHub Desktop.
function createHash() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 32; i++)
text += possible.charAt(Math.ceil(Math.random() * possible.length));
return text;
}
function preventCaching() {
var script = $('script[type="text/javascript"]'),
style = $('link[rel="stylesheet"]');
style.map(function(k,v) {
$(v).attr('href', $(v).attr('href') + '?' + createHash());
});
script.map(function(k,v) {
$(v).attr('src', $(v).attr('src') + '?' + createHash());
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment