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