我正在尝试在服务工作者的安装事件中使用标准技术添加一些静态页面以进行缓存:
self.addEventListener('install',function(event) {
event.waitUntil(
caches.open(static_cache).then(function(cache){
return cache.addAll([
'/',
'index.html',
'css/styles.css',
'js/dbhelper.js',
'js/main.js',
'js/restaurant_info.js'
])
})
)
})
但是当我查看缓存的项目时-我看到它们被缓存在相对路径下:
因此,当然,当获取事件针对完整路径时-缓存中将没有匹配项。知道为什么会这样吗?
答案 0 :(得分:1)
我可能会误会,但我认为开发工具缓存界面仅显示相对路径。但我相信它们已被完整路径缓存。
如果您记录缓存内容,您应该会看到完整路径。
例如,我的缓存界面显示“ /”,但是这两个都显示:
caches.match('https://offline-data-driven-pwa.firebaseapp.com/')
.then(res => console.log(res))
caches.match('/')
.then(res => console.log(res))