123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- this.workbox = this.workbox || {};
- this.workbox.recipes = (function (exports, registerRoute_js, StaleWhileRevalidate_js, CacheFirst_js, CacheableResponsePlugin_js, ExpirationPlugin_js, NetworkFirst_js, setCatchHandler_js, matchPrecache_js) {
- 'use strict';
- try {
- self['workbox:recipes:6.6.0'] && _();
- } catch (e) {}
-
-
- function googleFontsCache(options = {}) {
- const sheetCacheName = `${options.cachePrefix || 'google-fonts'}-stylesheets`;
- const fontCacheName = `${options.cachePrefix || 'google-fonts'}-webfonts`;
- const maxAgeSeconds = options.maxAgeSeconds || 60 * 60 * 24 * 365;
- const maxEntries = options.maxEntries || 30;
- registerRoute_js.registerRoute(({
- url
- }) => url.origin === 'https://fonts.googleapis.com', new StaleWhileRevalidate_js.StaleWhileRevalidate({
- cacheName: sheetCacheName
- }));
- registerRoute_js.registerRoute(({
- url
- }) => url.origin === 'https://fonts.gstatic.com', new CacheFirst_js.CacheFirst({
- cacheName: fontCacheName,
- plugins: [new CacheableResponsePlugin_js.CacheableResponsePlugin({
- statuses: [0, 200]
- }), new ExpirationPlugin_js.ExpirationPlugin({
- maxAgeSeconds,
- maxEntries
- })]
- }));
- }
-
- function warmStrategyCache(options) {
- self.addEventListener('install', event => {
- const done = options.urls.map(path => options.strategy.handleAll({
- event,
- request: new Request(path)
- })[1]);
- event.waitUntil(Promise.all(done));
- });
- }
-
-
- function imageCache(options = {}) {
- const defaultMatchCallback = ({
- request
- }) => request.destination === 'image';
- const cacheName = options.cacheName || 'images';
- const matchCallback = options.matchCallback || defaultMatchCallback;
- const maxAgeSeconds = options.maxAgeSeconds || 30 * 24 * 60 * 60;
- const maxEntries = options.maxEntries || 60;
- const plugins = options.plugins || [];
- plugins.push(new CacheableResponsePlugin_js.CacheableResponsePlugin({
- statuses: [0, 200]
- }));
- plugins.push(new ExpirationPlugin_js.ExpirationPlugin({
- maxEntries,
- maxAgeSeconds
- }));
- const strategy = new CacheFirst_js.CacheFirst({
- cacheName,
- plugins
- });
- registerRoute_js.registerRoute(matchCallback, strategy);
- if (options.warmCache) {
- warmStrategyCache({
- urls: options.warmCache,
- strategy
- });
- }
- }
-
-
- function staticResourceCache(options = {}) {
- const defaultMatchCallback = ({
- request
- }) => request.destination === 'style' || request.destination === 'script' || request.destination === 'worker';
- const cacheName = options.cacheName || 'static-resources';
- const matchCallback = options.matchCallback || defaultMatchCallback;
- const plugins = options.plugins || [];
- plugins.push(new CacheableResponsePlugin_js.CacheableResponsePlugin({
- statuses: [0, 200]
- }));
- const strategy = new StaleWhileRevalidate_js.StaleWhileRevalidate({
- cacheName,
- plugins
- });
- registerRoute_js.registerRoute(matchCallback, strategy);
- if (options.warmCache) {
- warmStrategyCache({
- urls: options.warmCache,
- strategy
- });
- }
- }
-
-
- 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_js.CacheableResponsePlugin({
- statuses: [0, 200]
- }));
- const strategy = new NetworkFirst_js.NetworkFirst({
- networkTimeoutSeconds,
- cacheName,
- plugins
- });
- registerRoute_js.registerRoute(matchCallback, strategy);
- if (options.warmCache) {
- warmStrategyCache({
- urls: options.warmCache,
- strategy
- });
- }
- }
-
-
- function offlineFallback(options = {}) {
- const pageFallback = options.pageFallback || 'offline.html';
- const imageFallback = options.imageFallback || false;
- const fontFallback = options.fontFallback || false;
- self.addEventListener('install', event => {
- const files = [pageFallback];
- if (imageFallback) {
- files.push(imageFallback);
- }
- if (fontFallback) {
- files.push(fontFallback);
- }
- event.waitUntil(self.caches.open('workbox-offline-fallbacks').then(cache => cache.addAll(files)));
- });
- const handler = async options => {
- const dest = options.request.destination;
- const cache = await self.caches.open('workbox-offline-fallbacks');
- if (dest === 'document') {
- const match = (await matchPrecache_js.matchPrecache(pageFallback)) || (await cache.match(pageFallback));
- return match || Response.error();
- }
- if (dest === 'image' && imageFallback !== false) {
- const match = (await matchPrecache_js.matchPrecache(imageFallback)) || (await cache.match(imageFallback));
- return match || Response.error();
- }
- if (dest === 'font' && fontFallback !== false) {
- const match = (await matchPrecache_js.matchPrecache(fontFallback)) || (await cache.match(fontFallback));
- return match || Response.error();
- }
- return Response.error();
- };
- setCatchHandler_js.setCatchHandler(handler);
- }
- exports.googleFontsCache = googleFontsCache;
- exports.imageCache = imageCache;
- exports.offlineFallback = offlineFallback;
- exports.pageCache = pageCache;
- exports.staticResourceCache = staticResourceCache;
- exports.warmStrategyCache = warmStrategyCache;
- return exports;
- }({}, workbox.routing, workbox.strategies, workbox.strategies, workbox.cacheableResponse, workbox.expiration, workbox.strategies, workbox.routing, workbox.precaching));
|