Workbox Cache First not caching properly

吃可爱长大的小学妹 提交于 2020-01-16 11:57:10

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!