I am using the Workbox CacheableResponsePlugin in a service worker definition to route cacheable and non-cacheable documents with two different caching strategies. If the header "pwa-cache-control: no-cache" is set I'd like to use the NetworkOnly strategy and in case the header is missing CacheFirst.
What actually happens though, all documents are handled by the NetworkOnly route, even for those where the pwa-cache-control header is missing. I could verify that in the debug view. Do I miss something here or is the header feature of the plugin broken?
If I remove the first route, the CacheFirst strategy is used as expected for all documents.
Btw, I am assuming that routes are considered in the order of being registered, correct?
Here is the respective section within sw.js
// don't cache pages with no-cache header
registerRoute(
({request}) => request.destination === 'document',
new NetworkOnly({
plugins: [
new CacheableResponsePlugin({
headers: {
'pwa-cache-control': 'no-cache',
},
}),
],
})
);
// all other pages cache first
registerRoute(
({request}) => request.destination === 'document',
new CacheFirst({
cacheName: 'html-cache',
plugins: [
new ExpirationPlugin({
maxAgeSeconds: 1 * 24 * 60 * 60,
}),
],
})
);