feat: improve caching
This commit is contained in:
parent
5ed3ecaf16
commit
079060b459
1 changed files with 10 additions and 4 deletions
|
@ -57,8 +57,14 @@ self.addEventListener('install', installEvent => {
|
|||
|
||||
self.addEventListener('fetch', fetchEvent => {
|
||||
fetchEvent.respondWith(
|
||||
caches.match(fetchEvent.request).then(res => {
|
||||
return res || fetch(fetchEvent.request);
|
||||
caches.open(service_worker).then(cache => {
|
||||
return cache.match(fetchEvent.request).then(response => {
|
||||
const fetchPromise = fetch(fetchEvent.request).then(networkResponse => {
|
||||
cache.put(fetchEvent.request, networkResponse.clone());
|
||||
return networkResponse;
|
||||
});
|
||||
return response || fetchPromise;
|
||||
});
|
||||
})
|
||||
)
|
||||
})
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue