mirror of
https://github.com/kevin-DL/sapper-template.git
synced 2026-01-12 02:15:17 +00:00
Do not cache with Cache API if cache mode is only-if-cached
The previous implementation tried to cache only-if-cached by changing request mode but it doesn't work because the property is readonly. However, caching responses cached with HTTP Cache again with Cache API does not make sense anyway. Just do not cache it, and leave it to HTTP cache.
This commit is contained in:
@@ -58,6 +58,8 @@ self.addEventListener('fetch', event => {
|
||||
}
|
||||
*/
|
||||
|
||||
if (event.request.cache === 'only-if-cached') return;
|
||||
|
||||
// for everything else, try the network first, falling back to
|
||||
// cache if the user is offline. (If the pages never change, you
|
||||
// might prefer a cache-first approach to a network-first one.)
|
||||
@@ -66,11 +68,6 @@ self.addEventListener('fetch', event => {
|
||||
.open(`offline${timestamp}`)
|
||||
.then(async cache => {
|
||||
try {
|
||||
if (event.request.cache === 'only-if-cache') {
|
||||
// workaround Chrome devtools bug https://github.com/sveltejs/sapper-template/issues/34
|
||||
event.request.mode = 'same-origin';
|
||||
}
|
||||
|
||||
const response = await fetch(event.request);
|
||||
cache.put(event.request, response.clone());
|
||||
return response;
|
||||
|
||||
Reference in New Issue
Block a user