Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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