mirror of
https://github.com/kevin-DL/sapper-template.git
synced 2026-01-20 13:35:11 +00:00
Merge pull request #70 from akihikodaki/master
Do not cache with Cache API if cache mode is only-if-cached
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
|
// for everything else, try the network first, falling back to
|
||||||
// cache if the user is offline. (If the pages never change, you
|
// cache if the user is offline. (If the pages never change, you
|
||||||
// might prefer a cache-first approach to a network-first one.)
|
// might prefer a cache-first approach to a network-first one.)
|
||||||
@@ -66,11 +68,6 @@ self.addEventListener('fetch', event => {
|
|||||||
.open(`offline${timestamp}`)
|
.open(`offline${timestamp}`)
|
||||||
.then(async cache => {
|
.then(async cache => {
|
||||||
try {
|
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);
|
const response = await fetch(event.request);
|
||||||
cache.put(event.request, response.clone());
|
cache.put(event.request, response.clone());
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
Reference in New Issue
Block a user