Created
November 10, 2012 04:19
-
-
Save twolfson/4049879 to your computer and use it in GitHub Desktop.
Health watcher
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
// 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