You can use navigator.onLine
to detect a network connection
setInterval(function() {
if (navigator.onLine) {
location.reload();
}
}, 120000); /* 120000 ~> 2 minutes */
otherwise, you may use instead an HEAD
ajax request to a same-domain resource and refresh the page only if the response return a 200/304
status, e.g.
setInterval(function() {
$.ajax({
url : "/favicon.ico", /* or other resource */
type : "HEAD"
})
.done(function() {
location.reload();
});
}, 120000); /* 120000 ~> 2 minutes */