问题
I am trying to build a Cache First strategy with workbox on a React + NextJS app, but i am facing a problem... I have the following rule:
workbox.routing.registerRoute(
new RegExp('/.*\/uploads|.*\/arquivos.*/'),
new workbox.strategies.CacheFirst({
cacheName: 'cache-first',
})
);
Looking at workbox log a got the following messages:
Router responding to
and
Using Cache First to respond
But nothing gets cached as can be seen on:
enter image description here
If I change the strategy from CacheFirst to NetworkFirst the files get cached and everything works as expected. Does anyone knows any issue related to that on workbox? or I am doing something wrong?
回答1:
I found the problem, cache first doesn't work with opaque responses, we have to use StaleWhileRevalidate in these cases, more info on:
https://blog.fullstacktraining.com/what-is-an-opaque-response/
来源:https://stackoverflow.com/questions/59039433/workbox-cache-first-not-caching-properly