Created
April 13, 2010 21:28
-
-
Save dbergey/365104 to your computer and use it in GitHub Desktop.
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
// checks every few secs to see if any source file is updated and reloads if needed | |
// reloadr.php should check mtimes of files you want to track and return max(mtimes). | |
// like this: | |
/* | |
<?php | |
$files = array_merge( | |
glob('*.php'), | |
glob('tests/*.php') | |
); | |
foreach ( $files as &$file ) $file = filemtime($file); | |
echo max($files); | |
?> | |
*/ | |
var reloadr = { | |
frequency: 2000, | |
fname: 'reloadr.php', | |
req: new XMLHttpRequest(), | |
ajax: function(url, callback) { | |
reloadr.req.open("GET", url, false); | |
reloadr.req.send(null); | |
if (reloadr.req.status == 200) callback.call(reloadr.req); | |
}, | |
go: function() { | |
window.loadTime = Date.parse(Date()) / 1000; | |
setInterval(function() { | |
reloadr.ajax(reloadr.fname, function() { | |
if (this.responseText > window.loadTime) location.reload(); | |
}); | |
}, reloadr.frequency); | |
} | |
}; | |
reloadr.go(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment