How to use the workbox-strategies.CacheFirst function in workbox-strategies

To help you get started, we’ve selected a few workbox-strategies examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ampproject / amp-sw / src / modules / amp-caching / index.ts View on Github external
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({
github ampproject / amp-sw / src / modules / link-prefetch / index.ts View on Github external
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,
        }),
      );
    });
  }
github bs-community / blessing-skin-server / resources / assets / src / scripts / sw.ts View on Github external
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',
github ampproject / amp-sw / src / modules / asset-caching / index.ts View on Github external
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);
    });
  }