2020-05-22 10:45:34 +09:00
|
|
|
import {registerRoute} from 'workbox-routing';
|
|
|
|
import {StaleWhileRevalidate} from 'workbox-strategies';
|
|
|
|
|
|
|
|
const cacheName = 'static-cache-v2';
|
|
|
|
|
2020-05-24 16:36:40 +09: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 10:45:34 +09:00
|
|
|
const cachedDestinations = new Set([
|
2020-05-24 16:36:40 +09:00
|
|
|
'font',
|
2020-05-22 10:45:34 +09:00
|
|
|
'manifest',
|
2020-05-24 16:36:40 +09:00
|
|
|
'paintworklet',
|
2020-05-22 10:45:34 +09:00
|
|
|
'script',
|
2020-05-24 16:36:40 +09:00
|
|
|
'sharedworker',
|
2020-05-22 10:45:34 +09:00
|
|
|
'style',
|
|
|
|
'worker',
|
|
|
|
]);
|
|
|
|
|
|
|
|
registerRoute(
|
|
|
|
({request}) => cachedDestinations.has(request.destination),
|
|
|
|
new StaleWhileRevalidate({cacheName}),
|
|
|
|
);
|