Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.__WB_DISABLE_DEV_LOGS = true;
// see https://developer.mozilla.org/en-US/docs/Web/API/RequestDestination for possible values
const cachedDestinations = new Set([
'font',
'manifest',
'paintworklet',
'script',
'sharedworker',
'style',
'worker',
]);
registerRoute(
({request}) => cachedDestinations.has(request.destination),
new StaleWhileRevalidate({cacheName}),
);
router.registerRoute(
UNVERSIONED_RUNTIME_RE,
new StaleWhileRevalidate({
cacheName: UNVERSIONED_CACHE_NAME,
plugins: [
new Plugin({
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
}),
],
}),
);
// Unversioned Extensions
router.registerRoute(
UNVERSIONED_EXTENSIONS_RE,
new StaleWhileRevalidate({
cacheName: UNVERSIONED_CACHE_NAME,
plugins: [
new Plugin({
maxAgeSeconds: 24 * 60 * 60, // 1 day
}),
],
}),
);
}
registerRoute(
/\/preview\/\d+/,
new CacheFirst({
cacheName: 'texture-preview-v2',
fetchOptions: {
credentials: 'omit',
},
plugins: [
new ExpirationPlugin({ maxAgeSeconds: oneWeek, purgeOnQuotaError: true }),
],
}),
)
registerRoute(
/\/app\/.*\.webp/,
new StaleWhileRevalidate({
cacheName: 'webp-resource-v1',
fetchOptions: {
credentials: 'omit',
},
}),
)
registerRoute(
/\/avatar\/\d+/,
new CacheFirst({
cacheName: 'avatar-v2',
fetchOptions: {
credentials: 'omit',
},
plugins: [new ExpirationPlugin({ maxAgeSeconds: oneWeek })],
}),
cacheName: AMP_ASSET_CACHE,
plugins: [
new AssetCachingPlugin({
maxEntries: assetCachingOption.maxEntries || 25,
denyList: assetCachingOption.denyList,
purgeOnQuotaError,
}),
],
};
switch (assetCachingOption.cachingStrategy) {
case 'NETWORK_FIRST':
cachingStrategy = new NetworkFirst(cachingConfig);
break;
case 'STALE_WHILE_REVALIDATE':
cachingStrategy = new StaleWhileRevalidate(cachingConfig);
break;
default:
cachingStrategy = new CacheFirst(cachingConfig);
break;
}
router.registerRoute(assetCachingOption.regexp, cachingStrategy);
});
}