2

Our web app was created using Jhipster with Webpack and using service workers to make it "installable" for users on their device. We use this workbox plugin setup for it in webpack.prod.js

 new WorkboxPlugin.GenerateSW({
  clientsClaim: true,
  skipWaiting: true,
  runtimeCaching: [{
    urlPattern: /\.(?:css|scss|js|ts|tsx|html)$/,
    handler: 'networkFirst',
    options: {
      cacheName: 'myCache',
      expiration: {
        maxAgeSeconds: 60 * 60 * 24
      },
      broadcastUpdate: {
        channelName: 'update-myCache'
      }
    }
  },
  {
    urlPattern: /\.(?:png|jpg|jpeg|svg|gif|eot|ttf|woff|woff2)$/,
    handler: 'staleWhileRevalidate',
    options: {
      cacheName: 'assetCache',
      broadcastUpdate: {
        channelName: 'update-assetCache'
      }
    }
  }]
})

Each time we release a new version, issues arise for users. All issues can be resolved by refreshing the browser. But we don't want that of course!

We are using webpack to add a unique hash to each file name. When inspecting the "workbox-precache" under the "application" tab in chrome devtools we can see that the new file name "...cf9b" has been loaded and cached, but still the old file "...c540" is shown to the user!

file names with correct new hash ending in "cf9b" and "time cached" is current time

white screen with loading... and old file getting "404 not found" in console

The console shows "404 not found" for the old version of the file, even if the new one exists in the "application" tab.

The "index.html" file visible in the "sources" tab is also clearly old and importing the old "main" and "vendors" files: enter image description here

Looking at the network tab, we see new files being fetched, but then ALSO an old file (that fails):

enter image description here

So the question is: Is there anything more we need to do to make the browser use the new versions of the files and not the old ones? To make the old files NOT show up in the "sources" tab as they do today. I've searched like crazy but the only things I find are "add version hash to files and all will be good" and we have already done that.

JavaDevSweden
  • 2,154
  • 2
  • 18
  • 29
  • If you're precaching your `index.html` and also performing lazy-loading of subresources, then you should have `skipWaiting: false`set. See https://pawll.glitch.me/ for an overview of why this is recommended, as well as similar answers on SO: https://stackoverflow.com/a/51716150/385997 – Jeff Posnick Dec 09 '21 at 22:26
  • Did you end to find a solution for this issue? I'm struggling with the same issue using Webpack – Toucouleur Jul 01 '22 at 09:26

0 Answers0