76 lines
2.0 KiB
HTML
76 lines
2.0 KiB
HTML
<!-- This is an Offline fall back page for Erant PWA -->
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
|
|
<title>You are offline</title>
|
|
|
|
<!-- Inline the page's stylesheet. -->
|
|
<style>
|
|
body {
|
|
font-family: 'Source Sans Pro';
|
|
margin: 2em;
|
|
}
|
|
|
|
h1 {
|
|
font-style: italic;
|
|
color: #4263eb;
|
|
font-size: 18px;
|
|
font-family: 'Source Sans Pro';
|
|
font-style: normal;
|
|
font-weight: 600;
|
|
line-height: 28px;
|
|
}
|
|
|
|
p {
|
|
margin-block: 1rem;
|
|
}
|
|
|
|
button {
|
|
display: block;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>You are offline</h1>
|
|
|
|
<p>Click the button below to try reloading.</p>
|
|
<button type="button">⤾ Reload</button>
|
|
|
|
<!-- Inline the page's JavaScript file. -->
|
|
<script>
|
|
// Manual reload feature.
|
|
document.querySelector("button").addEventListener("click", () => {
|
|
window.location.reload();
|
|
});
|
|
|
|
// Listen to changes in the network state, reload when online.
|
|
// This handles the case when the device is completely offline.
|
|
window.addEventListener('online', () => {
|
|
window.location.reload();
|
|
});
|
|
|
|
// 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.
|
|
async function checkNetworkAndReload() {
|
|
try {
|
|
const response = await fetch('.');
|
|
// Verify we get a valid response from the server
|
|
if (response.status >= 200 && response.status < 500) {
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
} catch {
|
|
// Unable to connect to the server, ignore.
|
|
}
|
|
window.setTimeout(checkNetworkAndReload, 2500);
|
|
}
|
|
|
|
checkNetworkAndReload();
|
|
</script>
|
|
</body>
|
|
</html> |