0

I recently turned a website into a PWA using workbox and added to my home screen on my android device. However, when I update the website, the PWA does not update on android.

Below is the code manifest.json code:

{"short_name":"SSPNG","name":"Security Shields PNG Limited","icons":[{"src":"/assets/img/fb-pro-pic0.png","type":"image/png","sizes":"512x512"},{"src":"/assets/img/fb-pro-pic0.png","type":"image/png","sizes":"512x512"}],"start_url":"/index.html","background_color":"#fff","theme_color":"#fff","display":"standalone","orientation":"portrait"}

Here is the service-worke registration code:

<script>
    if ('serviceWorker' in navigator) {
      window.addEventListener('load', () => {
        navigator.serviceWorker.register('/sw.js')
          .then(registration => {
            console.log('Service Worker registered! ');
          })
          .catch(err => {
            console.log('Registration failed  ', err);
          });
      });
    }
  </script>

I am looking for a solution where users don't need to manually clear the cache form browser app storage and that the PWA automatically gets updated. I think I used the cache fallback method and I am seeking an alternative relief that forcefully updates the cache in the existing PWA.

  • Does this answer your question? [When and how does a PWA update itself?](https://stackoverflow.com/questions/49739438/when-and-how-does-a-pwa-update-itself) – soroush Aug 23 '20 at 20:06

1 Answers1

0

I am afraid, you are mixing two things up:

  • The manifest.json only contains references to icon files, the start_url and scope.
  • Whereas the service-worker.js should contain an array with the paths to the HTML, CSS, JavaScript and other asset files of your PWA. Furthermore, the service-worker.js should also define event listeners/handlers for PWA install, activate/delete and fetch events.

Finally, what eventually triggers a PWA to automatically update is explained here.

Serge Stroobandt
  • 28,495
  • 9
  • 107
  • 102