Skip to content
This repository has been archived by the owner on Oct 13, 2022. It is now read-only.

Do not cache with Cache API if cache mode is only-if-cached #70

Merged
merged 1 commit into from
Jul 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions app/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand All @@ -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;
Expand Down