How to use the workbox-strategies.CacheOnly 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 GoogleChrome / samples / web-share / src / js / service-worker.js View on Github external
}

  // Use the MIME type of the first file shared to determine where we redirect.
  const routeToRedirectTo = [
    audioRoute,
    imagesRoute,
    videosRoute,
  ].find((route) => mediaFiles[0].type.startsWith(route.mimePrefix));

  const redirectionUrl = routeToRedirectTo ? `/#${routeToRedirectTo.href}` : '/';
  
  // After the POST succeeds, redirect to the main page.
  return Response.redirect(redirectionUrl, 303);
};

const cachedMediaHandler = new CacheOnly({
  cacheName,
  plugins: [
    // Support for cache requests that include a Range: header.
    new RangeRequestsPlugin(),
  ],
});

skipWaiting();
clientsClaim();

// This will be replaced by the list of files to precache by
// the `workbox injectManifest` build step.
precacheAndRoute(self.__WB_MANIFEST);

registerRoute(
  '/_share-target',