bug: dont cache index page with service worker

This commit is contained in:
Kieran 2023-01-20 11:59:27 +00:00
parent 194fd6beac
commit b583ea5ff0
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
1 changed files with 2 additions and 14 deletions

View File

@ -2,23 +2,13 @@
import { clientsClaim } from 'workbox-core';
import { ExpirationPlugin } from 'workbox-expiration';
import { precacheAndRoute, createHandlerBoundToURL } from 'workbox-precaching';
import { precacheAndRoute } from 'workbox-precaching';
import { registerRoute } from 'workbox-routing';
import { StaleWhileRevalidate, CacheFirst } from 'workbox-strategies';
clientsClaim();
precacheAndRoute(self.__WB_MANIFEST);
const fileExtensionRegexp = new RegExp('/[^/?]+\\.[^/]+$');
registerRoute(({ request, url }) => {
if (request.mode !== 'navigate' || url.pathname.startsWith('/_') || url.pathname.match(fileExtensionRegexp)) {
return false;
}
return true;
},
createHandlerBoundToURL(process.env.PUBLIC_URL + '/index.html')
);
const staticTypes = ["image", "video", "audio"]
registerRoute(({ request, url }) => url.origin === self.location.origin && staticTypes.includes(request.destination),
new StaleWhileRevalidate({
@ -40,6 +30,4 @@ self.addEventListener('message', (event) => {
if (event.data && event.data.type === 'SKIP_WAITING') {
self.skipWaiting();
}
});
// Any other custom service worker logic can go here.
});