Responsive web offline shows Youre offline after Browser refresh (F5)

0
Hello, we created a Responsive web offline profile for an existing app, which works good when there is no network connection. The only problem we got is, if the user refreshes in PWA or Browser. Then it switches to a page "You're offline" (offline.html under deployment/react-web/  or deployment/web/). Is there a possibility prevent this page or the refresh itself? Mendix Studio Version is 9.24.25 but it is not available in the dropdown.   Thanks in advance.
asked
1 answers
1

Unfortunately, refreshing the page in offline mode forces the browser to load the offline.html file because the Mendix runtime cannot reload the app without a network connection.

 

Disable Browser Refresh

Intercept refresh behavior by adding a beforeunload event handler in JavaScript. This prevents page reload when offline.

 

JS:

window.addEventListener('beforeunload', (event) => {
  if (!navigator.onLine) {
    event.preventDefault();
    event.returnValue = '';
  }
});

 

Other option could be, Instead of loading offline.html, redirect users to an in-app "Offline Mode" page using a Service Worker or custom routing logic.

answered