PWA: how to refresh content every time the app is opened

Viewed 564

I created a PWA app which sends API call to my domotic server and prints the response on the home page (e.g. outside temperature and vacuum robot status).

While all the data get refreshed at very first app opening, if I minimize the app whithout completely shutting it off I have no data refreshing at all.

I was wondering how to force a refresh every time the app gets re-opened without having to do it manually (no pull-down to refresh, no refresh-button).

1 Answers

Found myself the solution adding the following code in service worker:

self.addEventListener('visibilitychange', function() {
    if (document.visibilityState === 'visible') {
        console.log('APP resumed');
        window.location.reload();
    }
});
Related