Skip to content

Instantly share code, notes, and snippets.

@miripiruni
Forked from shinypb/gist:4485878
Last active October 23, 2015 15:20
Show Gist options
  • Save miripiruni/92ec93d5641156328c48 to your computer and use it in GitHub Desktop.
Save miripiruni/92ec93d5641156328c48 to your computer and use it in GitHub Desktop.
Bookmarklet to reload CSS without reloading the entire page
// Bookmarklet version (made using http://userjs.up.seesaa.net/js/bookmarklet.html)
javascript:(function(){$('link[rel="stylesheet"]').each(function(i,elem){var anchorTag=$('a').attr('href',elem.getAttribute('href'))[0];anchorTag.search="ts="+(+new Date);elem.href=anchorTag.href;})})()
(function(){
$('link[rel="stylesheet"]').each(function(i, elem) {
// Make an anchor tag with the stylesheet's href -- this is a weird/handy way of
// working with URLs in the browser.
var anchorTag = $('a').attr('href', elem.getAttribute('href'))[0];
// Rewrite the URL to have a cache busting parameter. This assumes
// that any query params weren't significant.
anchorTag.search = "ts=" + (+new Date);
// Update the stylesheet link
elem.href = anchorTag.href;
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment