How to use the workbox-strategies.NetworkFirst 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 / asset-caching / index.ts View on Github external
purgeOnQuotaError = assetCachingOption.purgeOnQuotaError;
      }
      const cachingConfig = {
        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);
    });
  }
github BeWelcome / rox / assets / js / sw.js View on Github external
import {precacheAndRoute} from 'workbox-precaching';
import {NetworkFirst} from 'workbox-strategies';
import {registerRoute} from 'workbox-routing';

precacheAndRoute(self.__WB_MANIFEST);

addEventListener("message", event => {
    if (event.data && event.data.type === "SKIP_WAITING") {
        skipWaiting();
    }
});

registerRoute(
    ({url}) => url.pathname === '/',
    new NetworkFirst()
);

registerRoute(
    ({url}) => url.pathname.startsWith('/message'),
    new NetworkFirst()
);

registerRoute(
    ({url}) => url.pathname.startsWith('/request'),
    new NetworkFirst()
);

registerRoute(
    ({url}) => url.pathname.startsWith('/members'),
    new NetworkFirst()
);