My website serves an app_offline.htm file when it is down for maintenance. I want to force clients to reload when they detect that this page is being served. This way my users see an app_offline page immediately instead of having to refresh.
I figured out how to send a request to the server in JavaScript...
const opts = { method: 'GET', headers: {} };
fetch('/', opts)
.then(function (response) {
console.log('response from server:', response);
});
Output:
I don't know how to check the response to see if it is my app_offline page. I tried this:
if (response.statusCode === 503)
window.location.href = window.location.href; // Reload the page
The problem with this approach is that I'm not sure if 503 error necessarily means that my app_offline page is being served. If the website is inaccessible for any other reason, then I want the user stay on the page.
If I could set the statusText
on the response, then I could check that. I couldn't figure out how to do it on a static page.