【问题标题】:Workbox: writing regular expression for url patternsWorkbox:为 url 模式编写正则表达式
【发布时间】:2019-09-07 08:28:25
【问题描述】:

我正在尝试预缓存路由。我已经成功地预缓存了主页使用

 workbox.precaching.precacheAndRoute(['/']);

这与主页的路线相匹配

workbox.routing.registerRoute(
 /^\/$/,
  new workbox.strategies.NetworkFirst({
    cacheName: 'static-resources',
  })
);

我还有其他顶级路线我想匹配但不知道如何匹配。

localhost/subcategory //subcategory and slug attached to it
localhost/product  //product and slug attached to it
localhost/product-single // and slug attached to it

上面的正则表达式怎么写

【问题讨论】:

    标签: javascript progressive-web-apps workbox sw-precache


    【解决方案1】:

    您可以使用https://regex101.com/ 来帮助您实现您想要的。

    ^localhost(\/.+)?$ 这样的正则表达式应该可以解决问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-26
      • 2020-11-06
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多