Javascript is so powerfull. Nowadays we can see that there are lots of web app being used offline with the PWA implementation. Thats because javascript has the ability to detect if the client is connected to the internet or not.
We can simple listen to the javascript window to know about the clients connectivity status. And we can simply perform anything we want after the listened value is satisfied.
window.addEventListener("online", function () {
//Online Listener
//Perform anything you want in your website
//When this online event is satisfied
});
window.addEventListener("offline", function () {
//Offline Listener
//Perform anything you want in your website
//When this offline event is satisfied
});