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