askvortsov1 / flarum-pwa

Progressive Web App support for Flarum
MIT License
34 stars 12 forks source link

Automatically refresh the offline page when the internet connection returns #24

Closed rafaucau closed 3 years ago

rafaucau commented 3 years ago

Sometimes a user may lose connection to the Internet while using the forum and then an offline page appears. Maybe it would be a good idea to add a script to the offline page that automatically refreshes the page when the Internet connection returns?

window.addEventListener('online', () => {
  location.reload();
});

https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine/onLine

Or:

setInterval(() => {
  if (navigator.onLine) {
    location.reload();
  }
}, 1000);

This checks every second if the user is online, if so it refreshes the page