Steps to reproduce the issue:
- The user visits the webpage, see the code below.
- The user closes Chrome.
- The device goes completely offline (turn all networking off manually).
- The user re-opens the browser while completely offline.
- Chrome automatically serves the last visited page, a saved copy of the webpage which says
Online? true, even after hitting refresh several times.
The only thing that tells the user that she/he is looking at some stale, completely unusable copy of the web page is this in the address bar:
Non-technical users can easily miss that, and are left wondering why the page is unusable... This is bad user experience.
Browser & device: Chrome 81 on Android 6 on an Acer Iconia Tab 10 A3-40 tablet.
The webpage is served over HTTPS (secure connection).
Code:
const setMsg = (flag) => {
const p = document.getElementById('msg')
p.innerHTML = '<b>Online?</b> ' + flag
}
setMsg(navigator.onLine)
window.addEventListener("online", () => {
setMsg(true)
})
window.addEventListener("offline", () => {
setMsg(false)
})
<p id='msg'> </p>
As far as I can tell:
- Chrome does not re-run any JavaScript in Step 5, even after hitting refresh.
- Chrome does not respect the
Cache-Control: private, no-storeeither; double-checked.
So far, the only way I could prevent this from happening is to register a service worker. When I have a service worker registered, the JavaScript is re-run and I can properly and clearly inform the user that she/he is offline.
Without a service worker, how can I prevent Chrome from loading a stale, unusable webpage when offline?
The usual "No internet" page with the dinosaur is appropriate, and that's what I was expecting with Cache-Control: no-store.

pageshowdoesn't help either, double-checked. As far as I can tell, Chrome does not rerun any JavaScript, even if you hit reload. In other words,pageshowfails for the same reason why my code fails: It is not re-run by the browser.cache-control: no-cache, no-store, must-revalidateas you suggested. Then, I cleared the browser cache completely, and repeated the experiment. Chrome happily restores the page with those cache control headers. Please test your own page as I describe it in the post, with the current version of Chrome. I am pretty sure your page will be restored too. If not: Are you serving your page over HTTPS (secure connection)?