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