Skip to content

Commit

Permalink
Add counter to delay reloading in each retry
Browse files Browse the repository at this point in the history
  • Loading branch information
thelovekesh committed Feb 15, 2022
1 parent aec344d commit 4245fa3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions wp-includes/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function wp_service_worker_offline_page_reload() {
return;
}
?>
<script>
<script type="module">
/**
* Listen to changes in the network state, reload when online.
* This handles the case when the device is completely offline.
Expand All @@ -191,6 +191,9 @@ function wp_service_worker_offline_page_reload() {
window.location.reload();
});

// Create a counter to implement exponential backoff.
let count = 0;

/**
* Check if the server is responding and reload the page if it is.
* This handles the case when the device is online, but the server is offline or misbehaving.
Expand All @@ -206,7 +209,7 @@ function wp_service_worker_offline_page_reload() {
} catch {
console.log('User is offline');
}
window.setTimeout(checkNetworkAndReload, 2500);
window.setTimeout(checkNetworkAndReload, Math.pow(2, count++) * 2500);
}
checkNetworkAndReload();
</script>
Expand Down

0 comments on commit 4245fa3

Please sign in to comment.