我想弄清楚如何在安装时缓存动态页面?我目前的页面是/product/1/view
安装ServiceWorker缓存
self.addEventListener('install', function (event) {
event.waitUntil(
caches.open('kiosk-assets').then(function (cache) {
return cache.addAll([
'/' // This is the problem it caches the origin path i need the current page cached. See register below
'/css/product.min.css'
])
}),
....
这里是我如何注册我的工人。这是登记在/product/1/view
window.navigator.serviceWorker.register('/sw.js', {scope: `/product/${id}/view`})
我可以改变我如何注册,如果这可能是一种可能性。
你从哪里注册SW?并且,注册是否成功,您所发布的内容如上? 您是否可以记录范围并查看其范围是否符合您的要求? –
在安装事件中,sw不知道它可能控制什么,甚至在注册和激活之后,它是否控制DOM来获取当前url。您可能必须在注册员和工作者之间建立消息线程并缓存消息 –