Reputation: 621
In my service worker I have:
console.log('register images')
workbox.routing.registerRoute(
// Cache image files
/.*\.(?:png|jpg|jpeg|svg|gif)/,
// Use the cache if it's available
workbox.strategies.staleWhileRevalidate({
// Use a custom cache name
cacheName:'image-cache'
})
);
(for example) but no such cache is being created. (but pre-caching is working)
I presume I'm missing something basic. Can't seem to find an example that fixes this.
Any help would be appreciated
Upvotes: 1
Views: 1183
Reputation: 621
It was the scope of the serviceworker.
I had sw.js
in dist/
. Once I moved it to the public root (so scope became /
all was good.
That answer was REALLY hard to find. Lots if rooting around in the haystack.
For loading offline, I now need to get the serviceworker to respond to navigation request for /
. I saw a pithy comment that among other things index.html
needs to be placed in precache manifest (without instructions). Now having fun looking for docs on this for WorkboxPlugin.InjectManifest
. :-(
Upvotes: 2