12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import { warmStrategyCache } from './warmStrategyCache';
- import { registerRoute } from 'workbox-routing/registerRoute.js';
- import { NetworkFirst } from 'workbox-strategies/NetworkFirst.js';
- import { CacheableResponsePlugin } from 'workbox-cacheable-response/CacheableResponsePlugin.js';
- import './_version.js';
- function pageCache(options = {}) {
- const defaultMatchCallback = ({ request }) => request.mode === 'navigate';
- const cacheName = options.cacheName || 'pages';
- const matchCallback = options.matchCallback || defaultMatchCallback;
- const networkTimeoutSeconds = options.networkTimeoutSeconds || 3;
- const plugins = options.plugins || [];
- plugins.push(new CacheableResponsePlugin({
- statuses: [0, 200],
- }));
- const strategy = new NetworkFirst({
- networkTimeoutSeconds,
- cacheName,
- plugins,
- });
-
- registerRoute(matchCallback, strategy);
-
- if (options.warmCache) {
- warmStrategyCache({ urls: options.warmCache, strategy });
- }
- }
- export { pageCache };
|