Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ampAssetsCaching() {
// Versioned Assets
router.registerRoute(
VERSIONED_ASSETS_RE,
new CacheFirst({
cacheName: VERSIONED_CACHE_NAME,
plugins: [
new Plugin({
maxAgeSeconds: 14 * 24 * 60 * 60, // 14 days
}),
],
}),
);
// Unversioned runtimes
router.registerRoute(
UNVERSIONED_RUNTIME_RE,
new StaleWhileRevalidate({
cacheName: UNVERSIONED_CACHE_NAME,
plugins: [
new Plugin({
linksRegExps.forEach(link => {
navigationRoute_.addDeniedUrls(link);
router.registerRoute(
link,
new CacheFirst({
cacheName: AMP_PREFETCHED_LINKS,
plugins: [
new AmpPrefetchPlugin({
maxEntries: 10,
maxAgeSeconds: maxAgeSecondsInCache,
postDelete: (url: string) => {
const linkRE = convertUrlToRegExp(cleanHostInfoFromUrl(url));
navigationRoute_.removeDeniedUrls(linkRE);
},
}),
],
networkTimeoutSeconds: 0.5,
}),
);
});
}
StaleWhileRevalidate,
NetworkOnly,
} from 'workbox-strategies'
import { ExpirationPlugin } from 'workbox-expiration'
const oneWeek = 7 * 24 * 3600
if (process.env.NODE_ENV === 'development') {
registerRoute(/\.js/, new NetworkOnly())
registerRoute(/\.css/, new NetworkOnly())
}
//#region Pictures
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',
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);
});
}