How to disable warnings for workbox-webpack-plugin for generated service worker

1.7k views Asked by At

I use GenerateSw class for my worker generation. It works fine, but i need to precache some resources that not handled by webpack for offline page, so i use:

additionalManifestEntries: [
    '/offline',
    'https://static.express/img/laksjhdaskldfjlaljsafsp/connection-lost.svg'
]

but i'm facing this warnings, even though mode property is set to prod. enter image description here

Question: Can i hide them?

1

There are 1 answers

2
Jeff Posnick On BEST ANSWER

You can avoid these warnings by switching to objects with url: properties, and revision: null properties for each, to indicate that they are already uniquely revisioned based on their URLs.

additionalManifestEntries: [
  {url: '/offline', revision: null},
  {url: 'https://static.express/img/.../connection-lost.svg', revision: null},
]

But... if you do that, and your URLs don't actually contain any unique revision information in them, then your users will end up "stuck" with an old copy of, e.g., /offline indefinitely, even when you make changes to /offline and redeploy. That's why Workbox makes it "hard" to do this.

A better approach for caching additional URLs is to set up a runtime caching route that will use a specific strategy on them, and potentially "warm" that strategy cache using these techniques. Using, e.g., a StaleWhileRevalidate strategy for those URLs will ensure that they will eventually be updated.