我想弄清楚如何在安裝時緩存動態頁面?我目前的頁面是/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。您可能必須在註冊員和工作者之間建立消息線程並緩存消息 –