Created
September 13, 2012 00:40
-
-
Save marioizquierdo/3711034 to your computer and use it in GitHub Desktop.
Press Ctrl+E to reload page CSS
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() { | |
// Reload All Stylesheets | |
var reloadCSS = function() { | |
var $stylesheets; | |
$stylesheets = $('link[rel=stylesheet]'); | |
$stylesheets.each(function(i, el) { | |
var $stylesheet, href, newHref, noCacheToken; | |
$stylesheet = $(el); | |
href = $stylesheet.attr('href'); | |
noCacheToken = (new Date).getTime(); | |
if (href.indexOf("nocache") >= 0) { | |
newHref = href.replace(/nocache=\d+/, "nocache=" + noCacheToken); | |
} else { | |
newHref = "" + href + (href.indexOf('?') >= 0 ? '&' : '?') + "nocache=" + noCacheToken; | |
} | |
$stylesheet.attr('href', newHref); | |
}); | |
}; | |
// Reload CSS when pressing ctrl+e (cmd+e on mac) | |
$(window).keydown(function(e) { | |
if (e.which === 69 && (e.metaKey || e.ctrlKey)) { | |
reloadCSS(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It uses jQuery.
The idea is listen for Crtl+E (which is very close to Crtl+R) to reload ONLY the stylesheets in the page.
This is non intrusive, it doesn't require any configuration in the server at all, it plays nicely with Rails Asset Pipeline, and it definitely speeds up CSS development.
It won't update the CSS in real time, for that you should look at Guard LiveReload or similar