service-workerprogressive-web-appsworkboxworkbox-webpack-plugin

workbox v5 - how to version service worker?


In v4 we could use precacheManifestFilename with the workbox webpack plugin to put a version in our manifest name, which was imported into the SW and thereby versioned it. Now that the manifest is inlined and the option removed, what is the new way to version the SW? I can think of some ways that will survive minification but they seem hacky. Should we version our cache names??


Solution

  • You shouldn't version your service worker's filename/URL.

    If any of your webpack assets change in between service worker deployments, the inlined information in the precache manifest stored in the main service worker file will get updated. When the browser does its byte-for-byte check for new contents in the service worker file, the updated inline manifest will trigger the update flow.

    This will give you the behavior you expect.

    (This is also how the precache manifests have historically worked with non-webpack Workbox build tools, which have always inlined the manifest in the top-level service worker file.)