You could use an ajax
check for a tiny resource ahead of time, something like:
$(document).ready(function() {
setInterval(maybeRefresh, 66000);
function maybeRefresh() {
$.ajax({
url: "/path/to/tiny/resource",
type: "GET",
success: function() {
// That worked, do the full refresh
location.reload();
}
});
}
});
...but I would tend to think you'd be better off just load
ing the updated content instead. Put all of the primary content in an element with the id
"main"
, then:
$(document).ready(function() {
setInterval(function() {
$("#main").load("/path/to/new/content");
}, 66000);
});
That replaces the content of the #main
element with the content received from the GET
to /path/to/new/content
. If the GET
fails, no update.
I would probably also use a chained setTimeout
instead of a setInterval
and handle errors by trying to refresh more aggressively. Something like:
$(document).ready(function() {
setTimeout(refresh, 66000);
function refresh() {
$.ajax({
url: "/path/to/new/content",
type: "GET",
success: function(html) {
// Success, update the content
$("#main").html(html);
// Reload in 66 seconds
setTimeout(refresh, 66000);
},
error: function() {
// Failed, try again in five seconds
setTimeout(refresh, 5000);
}
});
}
});