How to use the workbox-core/_private/cacheNames.js.cacheNames.getPrecacheName function in workbox-core

To help you get started, we’ve selected a few workbox-core 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 GoogleChrome / workbox / packages / workbox-precaching / src / utils / addFetchListener.ts View on Github external
export const addFetchListener = ({
  ignoreURLParametersMatching = [/^utm_/],
  directoryIndex = 'index.html',
  cleanURLs = true,
  urlManipulation,
}: FetchListenerOptions = {}) => {
  const cacheName = cacheNames.getPrecacheName();

  // See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705
  self.addEventListener('fetch', ((event: FetchEvent) => {
    const precachedURL = getCacheKeyForURL(event.request.url, {
      cleanURLs,
      directoryIndex,
      ignoreURLParametersMatching,
      urlManipulation,
    });
    if (!precachedURL) {
      if (process.env.NODE_ENV !== 'production') {
        logger.debug(`Precaching did not find a match for ` +
          getFriendlyURL(event.request.url));
      }
      return;
    }
github GoogleChrome / workbox / packages / workbox-routing / src / registerNavigationRoute.ts View on Github external
export const registerNavigationRoute = (cachedAssetUrl: string,
    options: NavigationRouteOptions = {}): NavigationRoute => {
  if (process.env.NODE_ENV !== 'production') {
    assert!.isType(cachedAssetUrl, 'string', {
      moduleName: 'workbox-routing',
      funcName: 'registerNavigationRoute',
      paramName: 'cachedAssetUrl',
    });
  }

  const cacheName = cacheNames.getPrecacheName(options.cacheName);
  const handler = async () => {
    try {
      const response = await caches.match(cachedAssetUrl, {cacheName});

      if (response) {
        return response;
      }

      // This shouldn't normally happen, but there are edge cases:
      // https://github.com/GoogleChrome/workbox/issues/1441
      throw new Error(`The cache ${cacheName} did not have an entry for ` +
          `${cachedAssetUrl}.`);
    } catch (error) {
      // If there's either a cache miss, or the caches.match() call threw
      // an exception, then attempt to fulfill the navigation request with
      // a response from the network rather than leaving the user with a
github GoogleChrome / workbox / packages / workbox-precaching / src / cleanupOutdatedCaches.ts View on Github external
self.addEventListener('activate', ((event: ExtendableEvent) => {
    const cacheName = cacheNames.getPrecacheName();

    event.waitUntil(deleteOutdatedCaches(cacheName).then((cachesDeleted) => {
      if (process.env.NODE_ENV !== 'production') {
        if (cachesDeleted.length > 0) {
          logger.log(`The following out-of-date precaches were cleaned up ` +
              `automatically:`, cachesDeleted);
        }
      }
    }));
  }) as EventListener);
};
github GoogleChrome / workbox / packages / workbox-precaching / src / PrecacheController.ts View on Github external
constructor(cacheName?: string) {
    this._cacheName = cacheNames.getPrecacheName(cacheName);
    this._urlsToCacheKeys = new Map();
    this._urlsToCacheModes = new Map();
    this._cacheKeysToIntegrities = new Map();
  }