feat: improve caching

This commit is contained in:
grandeljay 2023-09-24 13:04:00 +02:00
parent 5ed3ecaf16
commit 079060b459

View file

@ -57,8 +57,14 @@ self.addEventListener('install', installEvent => {
self.addEventListener('fetch', fetchEvent => { self.addEventListener('fetch', fetchEvent => {
fetchEvent.respondWith( fetchEvent.respondWith(
caches.match(fetchEvent.request).then(res => { caches.open(service_worker).then(cache => {
return res || fetch(fetchEvent.request); 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;
});
}) })
);
});