Skip to content

Instantly share code, notes, and snippets.

@ernestom
Created June 27, 2012 23:17
Show Gist options
  • Save ernestom/3007518 to your computer and use it in GitHub Desktop.
Save ernestom/3007518 to your computer and use it in GitHub Desktop.
HTML/JS Apology page - retry self load
<!doctype html>
<html>
<head><meta charset="utf-8"></head>
<body>
<div id="loading">
<h2>Cargando información...</h2>
<h3>Esto puede tomar unos minutos</h3>
</div>
<div id="service-unavailable">
<h2>Por favor intente más tarde, disculpe las molestias</h2>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
(function() {
var retryIntervalSeconds = 60,
retryIncrementFactor = 1.2,
maxRetryAttempts = 3;
var url = self.location.href,
attempts = 0;
function retry() {
$.get(url, function() {
self.location.reload();
}).error(function() {
//console.log(new Date())
// Retry....
attempts++;
if (attempts <= maxRetryAttempts) {
if (attempts > 1) {
retryIntervalSeconds *= retryIncrementFactor;
}
setTimeout(retry, retryIntervalSeconds * 1000);
return;
}
// No attempts left, give up
$('#loading').hide();
$('#service-unavailable').show();
});
}
retry();
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment