Skip to content

Instantly share code, notes, and snippets.

@esson
Last active December 15, 2015 10:18
Show Gist options
  • Save esson/5244291 to your computer and use it in GitHub Desktop.
Save esson/5244291 to your computer and use it in GitHub Desktop.
This little snippet reloads all external stylesheets of a document. Perfect as a bookmarklet.
//javascript:
(function($){
function css() {
$('link[rel=stylesheet]').each(function(){
var $link=$(this);
var i=$link.attr('href').indexOf('?');
$link.clone().attr('href', $link.attr('href').substr(0, i > 0 ? i : undefined) + ('?' + Math.random()).replace('.', '')).load(function(){
$link.remove();
}).appendTo('head');
})
}
if (!$) {
var s=document.createElement("script");
s.setAttribute("src", "http://code.jquery.com/jquery.js");
document.getElementsByTagName("body")[0].appendChild(s);
setTimeout(css, 100);
} else {
css();
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment