PWA is not updated on the new production version on mobile devices

I am developing a desktop and mobile PWA using Ionic 3 / Angular 4. I am posting it on Amazon's https server. The application is open through the desktop browser, mobile browser or the home screen icon on mobile devices.

When I publish a new version and open the address in the desktop browser, I get the latest version of my application. When I publish a new version and open it through a mobile browser or the home screen icon, I get an old version of my application.

I thought that PWA should manage its own version.

How can I force update the application on mobile devices?

+5
source share
1 answer

As pointed out by @rory_za, you need to use a service worker as it disables the offline function, push notifications, background content updates, content caching, and much more. To enable a service worker in your web application, you can add the following to your index.html :

 <script> if ('serviceWorker' in navigator) { navigator.serviceWorker.register('service-worker.js') .then(() => console.log('service worker installed')) .catch(err => console.log('Error', err)); } </script> 

If the browser supports service workers, you need to register your service-worker.js . This returns the promise that we can handle the way we want.

0
source

All Articles