Skip to content

Instantly share code, notes, and snippets.

@twolfson
Created November 10, 2012 04:19
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 twolfson/4049879 to your computer and use it in GitHub Desktop.
Save twolfson/4049879 to your computer and use it in GitHub Desktop.
Health watcher
// Grab the current pid
$.get('/health', function (health) {
var pid = health.pid;
// Watch the health to see if it changes
setInterval(function () {
// If it does, refresh the page
$.get('/health', function (health) {
if (health.pid !== pid) {
location.reload();
}
});
}, 1e3);
});
// Re-grab the CSS now too
$('link[rel="stylesheet"]').each(function () {
var stylesheet = this,
href = stylesheet.href;
$.get(href, function (origCSS) {
// Watch the health to see if it changes
setInterval(function () {
// If it does, reload the CSS
$.get(href, function (css) {
if (origCSS !== css) {
var href = stylesheet.href;
stylesheet.href += href.indexOf('?') > -1 ? '1' : '?1';
origCSS = css;
}
});
}, 1e3);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment