Skip to content

Instantly share code, notes, and snippets.

@IOZ
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IOZ/a0f18d9d41bdfd03e4da to your computer and use it in GitHub Desktop.
Save IOZ/a0f18d9d41bdfd03e4da to your computer and use it in GitHub Desktop.
css auto reloader
/**
* Css auto reload
* NOTE!!! remove on production
*/
(function() {
'use strict';
var CssReload = {
config: {
keyCode: 83
},
init: function() {
this.link = $('link[href*="style.css"]');
this.unix = null;
this.href = null;
this.event();
},
event: function() {
$(window).on('keydown', this.reloadStyle.bind(this));
},
reloadStyle: function(e) {
if( e.keyCode === this.config.keyCode
&& localStorage.getItem('dev') == 1 ){
this._refreshStyle();
}
},
_refreshStyle: function() {
this.href = this.link.attr('href');
this.unix = new Date().getTime();
this.href = /\?/.test(this.href) ? this.href.split('?')[0] : this.href;
this.link.attr('href', this.href + '?' + this.unix);
}
};
window.CssReload = CssReload;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment