Last active
December 10, 2015 20:28
-
-
Save matijs/4488626 to your computer and use it in GitHub Desktop.
Bookmarklet to reload CSS without reloading the page… in old-fashioned browsers.
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
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())}}})(); |
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() { | |
// 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