How to use the workbox-strategies.StaleWhileRevalidate 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 go-gitea / gitea / web_src / js / serviceworker.js View on Github external
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}),
);
github ampproject / amp-sw / src / modules / amp-caching / index.ts View on Github external
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
          }),
        ],
      }),
    );
  }
github bs-community / blessing-skin-server / resources / assets / src / scripts / sw.ts View on Github external
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 })],
  }),
github ampproject / amp-sw / src / modules / asset-caching / index.ts View on Github external
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);
    });
  }