2020-05-22 03:45:34 +02:00
|
|
|
import {registerRoute} from 'workbox-routing';
|
|
|
|
import {StaleWhileRevalidate} from 'workbox-strategies';
|
|
|
|
|
|
|
|
const cacheName = 'static-cache-v2';
|
|
|
|
|
2020-05-24 09:36:40 +02:00
|
|
|
// disable workbox debug logging in development, remove when debugging the service worker
|
|
|
|
self.__WB_DISABLE_DEV_LOGS = true;
|
|
|
|
|
|
|
|
// see https://developer.mozilla.org/en-US/docs/Web/API/RequestDestination for possible values
|
2020-05-22 03:45:34 +02:00
|
|
|
const cachedDestinations = new Set([
|
2020-05-24 09:36:40 +02:00
|
|
|
'font',
|
2020-05-22 03:45:34 +02:00
|
|
|
'manifest',
|
2020-05-24 09:36:40 +02:00
|
|
|
'paintworklet',
|
2020-05-22 03:45:34 +02:00
|
|
|
'script',
|
2020-05-24 09:36:40 +02:00
|
|
|
'sharedworker',
|
2020-05-22 03:45:34 +02:00
|
|
|
'style',
|
|
|
|
'worker',
|
|
|
|
]);
|
|
|
|
|
|
|
|
registerRoute(
|
|
|
|
({request}) => cachedDestinations.has(request.destination),
|
|
|
|
new StaleWhileRevalidate({cacheName}),
|
|
|
|
);
|