workbox-strategies#NetworkFirst JavaScript Examples

The following examples show how to use workbox-strategies#NetworkFirst. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: service-worker.js    From Queen with MIT License 6 votes vote down vote up
registerRoute(
  new RegExp(getUrlRegexJson(self.location.origin)),
  new NetworkFirst({
    cacheName: configurationCacheName,
    plugins: [
      new CacheableResponsePlugin({
        statuses: [0, 200],
      }),
    ],
  })
);
Example #2
Source File: sw-template.js    From Pf2eTools with MIT License 6 votes vote down vote up
/*
the base case route - for images that have fallen through every other route
this is external images, for homebrew as an example
*/
registerRoute(({request}) => request.destination === "image", new NetworkFirst({
	cacheName: "external-image-cache",
	plugins: [
		// this is a safeguard against an utterly massive cache - these numbers may need tweaking
		new ExpirationPlugin({maxAgeSeconds: 7 /* days */ * 24 * 60 * 60, maxEntries: 100, purgeOnQuotaError: true}),
	],
}));
Example #3
Source File: service-worker.js    From pack11ty with MIT License 6 votes vote down vote up
// Pages
// Try to get fresh HTML from network, but don't wait for more than 2 seconds
registerRoute(
  ({ request }) => request.destination === 'document',
  new NetworkFirst({
    cacheName: 'pages',
    networkTimeoutSeconds: 2,
    plugins: [new BroadcastUpdatePlugin()],
  })
);
Example #4
Source File: sw.js    From rctf with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
registerRoute(
  ({ url }) => url.pathname === '/api/v1/challs',
  new NetworkFirst()
)
Example #5
Source File: sw.js    From gk6x_gui with MIT License 5 votes vote down vote up
registerRoute(
    new RegExp('\/(\\?.+)?$'),
    new NetworkFirst()
);
Example #6
Source File: sw.js    From gk6x_gui with MIT License 5 votes vote down vote up
registerRoute(
    new RegExp('\\.(html|css|js|json|jpe?g|png|gif|webp|svg)(\\?.+)?$'),
    new NetworkFirst()
);