Skip to content

Instantly share code, notes, and snippets.

@matijs
Last active December 10, 2015 20:28
Show Gist options
  • Save matijs/4488626 to your computer and use it in GitHub Desktop.
Save matijs/4488626 to your computer and use it in GitHub Desktop.
Bookmarklet to reload CSS without reloading the page… in old-fashioned browsers.
javascript:void (function(){var c=document.getElementsByTagName("link");for(var d=0,a=c.length;d<a;d++){if(c[d].rel.toLowerCase().indexOf("stylesheet")>=0&&c[d].href){var b=c[d].href.replace(/(&|\??)reload=\d+/,"");c[d].href=b+(b.indexOf("?")>=0?"&":"?")+"reload="+(new Date().valueOf())}}})();
(function() {
// grab a nodeList of link elements
var nodeList = document.getElementsByTagName("link");
// iterate over it
for (var i = 0, len = nodeList.length; i < len; i++) {
// cherry pick the ones that are stylesheets with a href
if (nodeList[i].rel.toLowerCase().indexOf('stylesheet') >= 0 && nodeList[i].href) {
// remove our cache buster if present
var href = nodeList[i].href.replace(/(&|\??)reload=\d+/, "");
// add cache buster while preserving existing params
nodeList[i].href = href + (href.indexOf("?") >= 0 ? "&" : "?") + 'reload=' + (new Date().valueOf());
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment