How to use the workbox-routing.registerRoute function in workbox-routing

To help you get started, we’ve selected a few workbox-routing 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,
github ampproject / amp-sw / src / modules / amp-caching / index.ts View on Github external
// Unversioned runtimes
    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 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({
            maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
          }),
        ],
      }),
    );

    // Unversioned Extensions
    router.registerRoute(
      UNVERSIONED_EXTENSIONS_RE,
      new StaleWhileRevalidate({
        cacheName: UNVERSIONED_CACHE_NAME,
github bs-community / blessing-skin-server / resources / assets / src / scripts / sw.ts View on Github external
/.*cdn\.jsdelivr\.net/,
  new CacheFirst({
    cacheName: 'jsdelivr-v1',
    fetchOptions: {
      credentials: 'omit',
      mode: 'cors',
    },
    plugins: [
      new ExpirationPlugin({ maxAgeSeconds: oneWeek, purgeOnQuotaError: true }),
    ],
  }),
)
//#endregion

//#region JavaScript files
registerRoute(
  /.+\/app\/\w{2,3}\.\w{7}\.js$/,
  new CacheFirst({
    cacheName: 'javascript-v1',
    fetchOptions: {
      credentials: 'omit',
      mode: 'cors',
    },
    plugins: [
      new ExpirationPlugin({ maxAgeSeconds: oneWeek, purgeOnQuotaError: true }),
    ],
  }),
)
registerRoute(
  /.+\/plugins\/.+\.js$/,
  new StaleWhileRevalidate({
    cacheName: 'javascript-v1',
github ampproject / amp-sw / src / modules / document-caching / index.ts View on Github external
new AmpDocumentCachablePlugin({
              maxEntries: documentCachingOptions.maxDocumentsInCache || 10,
              maxAgeSeconds:
                documentCachingOptions.maxAgeSecondsforDocumentsInCache ||
                5 * 24 * 60 * 60,
              allowedNonAMPPages: documentCachingOptions.allowedNonAMPPages,
            }),
          ],
          networkTimeoutSeconds: documentCachingOptions.timeoutSeconds,
        },
        fallbackOfflinePageUrl,
      ),
      navigationPreloadOptions,
    );

    router.registerRoute(navRoute);

    return navRoute;
  }
github bs-community / blessing-skin-server / resources / assets / src / scripts / sw.ts View on Github external
/.+\/plugins\/.+\.css$/,
  new StaleWhileRevalidate({
    cacheName: 'stylesheet-v1',
    fetchOptions: {
      credentials: 'omit',
      mode: 'cors',
    },
    plugins: [
      new ExpirationPlugin({ maxAgeSeconds: oneWeek, purgeOnQuotaError: true }),
    ],
  }),
)
//#endregion

//#region Fonts
registerRoute(
  ({ request }) => request.destination === 'font',
  new StaleWhileRevalidate({
    cacheName: 'font-v1',
    fetchOptions: {
      credentials: 'omit',
      mode: 'cors',
    },
    plugins: [new ExpirationPlugin({ maxEntries: 12 })],
  }),
)
//#endregion
github ampproject / amp-sw / src / modules / asset-caching / index.ts View on Github external
],
      };

      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 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
import { registerRoute } from 'workbox-routing'
import {
  CacheFirst,
  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 }),
    ],
  }),
)

workbox-routing

A service worker helper library to route request URLs to handlers.

MIT
Latest version published 29 days ago

Package Health Score

97 / 100
Full package analysis