如何返回缓存并带有离线消息?这可行吗?
我目前的代码只是简单地返回缓存:
const cachedFetch = request => request.method != 'GET' ?
fetch(request) :
caches.open("demo").then(cache =>
cache.match(request).then(resp => {
if(!!resp) {
console.log('cache', request.url)
return resp;// how to send custom message back with resp
} else {
console.log('not in cache', request.url)
return fetch(request).then(response => {
return response
})
}
})
)
self.addEventListener('fetch', event => event.respondWith(
cachedFetch(event.request)
)
)