Skip to content

Instantly share code, notes, and snippets.

@latortuga
Forked from mikelikespie/refresh_css.js
Created October 27, 2010 19:26
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 latortuga/649762 to your computer and use it in GitHub Desktop.
Save latortuga/649762 to your computer and use it in GitHub Desktop.
CSS reload bookmarklet
/*
Add a bookmark to this
javascript:(function(){var c=document.getElementsByTagName("link");for(var d=0;d<c.length;d++){var a=c[d];if(a.type=="text/css"){var e="css_buster_"+Math.floor(Math.random()*1000000000);var g=a.href.split("?",1);var f;if(g.length>1){var b=g[1].indexOf("&")==-1;if(b){f=e}else{f=g[1]+"&"+e}}else{f=e}a.href=g[0]+"?"+f}}})();
*/
(function() {
var links = document.getElementsByTagName('link');
for (var i = 0; i < links.length; i++) {
var l = links[i];
if (l.type == 'text/css') {
var rand_n = 'css_buster_' + Math.floor(Math.random() * 1000000000);
var splitted = l.href.split('?', 1);
var new_query_string;
// Does it already have a query string?
if (splitted.length > 1) {
// does it have params or just a cache buster
var has_amp = splitted[1].indexOf('&') == -1; // is it a query string?
// if it's just a cache buster, swap it out
if (has_amp) {
new_query_string = rand_n;
} else {
new_query_string = splitted[1] + '&' + rand_n;
}
} else {
new_query_string = rand_n;
}
l.href = splitted[0] + '?' + new_query_string;
}
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment