小编Sol*_*lar的帖子

Workbox SW:运行时缓存直到第二次重新加载才起作用

我是服务人员和工作箱的新手。我目前正在使用工作箱来预缓存我的静态资产文件,该文件可以正常工作,并且我希望在运行时也可以缓存我的其他第三方URL,但是直到页面上第二次重新加载后,我的第三方URL才起作用:(

下面显示的是我的服务人员代码的副本,请注意,我故意替换了原始链接到abc.domain.com的内容:)

workbox.routing.registerRoute(
  //get resources from any abc.domain.com/
  new RegExp('^https://abc.(?:domain).com/(.*)'),
  /*
  *respond with a cached response if available, falling back to the network request if it’s not cached. 
  *The network request is then used to update the cache.
  */
  workbox.strategies.staleWhileRevalidate({
    cacheName: 'Bill Resources',
    maxEntries: 60,
    maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days
  }),
); 

workbox.routing.registerRoute(
  new RegExp('^https://fonts.(?:googleapis|gstatic).com/(.*)'),
  //serve from network first, if not availabe then cache
  workbox.strategies.networkFirst(),
); 

workbox.routing.registerRoute(
  new RegExp('^https://use.(?:fontawesome).com/(.*)'),
  //serve from network first, if …
Run Code Online (Sandbox Code Playgroud)

caching progressive-web-apps workbox

6
推荐指数
1
解决办法
1365
查看次数

标签 统计

caching ×1

progressive-web-apps ×1

workbox ×1