@serwist/recipes 9.5.14 → 9.5.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -12
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +6 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { RouteMatchCallback, Serwist, SerwistPlugin, Strategy } from "serwist";
|
|
2
|
-
//#region src/googleFontsCache.d.ts
|
|
3
2
|
interface GoogleFontCacheOptions {
|
|
4
3
|
/**
|
|
5
4
|
* A {@linkcode Serwist} instance.
|
|
@@ -24,8 +23,6 @@ interface GoogleFontCacheOptions {
|
|
|
24
23
|
* @param options
|
|
25
24
|
*/
|
|
26
25
|
export declare const googleFontsCache: ({ serwist, cachePrefix, maxAgeSeconds, maxEntries }: GoogleFontCacheOptions) => void;
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region src/imageCache.d.ts
|
|
29
26
|
interface ImageCacheOptions {
|
|
30
27
|
/**
|
|
31
28
|
* A {@linkcode Serwist} instance.
|
|
@@ -62,8 +59,6 @@ interface ImageCacheOptions {
|
|
|
62
59
|
* @param options
|
|
63
60
|
*/
|
|
64
61
|
export declare const imageCache: ({ serwist, cacheName, matchCallback, maxAgeSeconds, maxEntries, plugins, warmCache }: ImageCacheOptions) => void;
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region src/offlineFallback.d.ts
|
|
67
62
|
interface OfflineFallbackOptions {
|
|
68
63
|
/**
|
|
69
64
|
* A {@linkcode Serwist} instance.
|
|
@@ -85,11 +80,10 @@ interface OfflineFallbackOptions {
|
|
|
85
80
|
/**
|
|
86
81
|
* An implementation of the [comprehensive fallbacks recipe](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#comprehensive_fallbacks).
|
|
87
82
|
* Be sure to include the fallbacks in your precache injection.
|
|
83
|
+
|
|
88
84
|
* @param options
|
|
89
85
|
*/
|
|
90
86
|
export declare const offlineFallback: ({ serwist, pageFallback, imageFallback, fontFallback }: OfflineFallbackOptions) => void;
|
|
91
|
-
//#endregion
|
|
92
|
-
//#region src/pageCache.d.ts
|
|
93
87
|
interface PageCacheOptions {
|
|
94
88
|
/**
|
|
95
89
|
* A {@linkcode Serwist} instance.
|
|
@@ -124,8 +118,6 @@ interface PageCacheOptions {
|
|
|
124
118
|
* @param options
|
|
125
119
|
*/
|
|
126
120
|
export declare const pageCache: ({ serwist, cacheName, matchCallback, networkTimeoutSeconds, plugins, warmCache }: PageCacheOptions) => void;
|
|
127
|
-
//#endregion
|
|
128
|
-
//#region src/staticResourceCache.d.ts
|
|
129
121
|
interface StaticResourceOptions {
|
|
130
122
|
/**
|
|
131
123
|
* A {@linkcode Serwist} instance.
|
|
@@ -158,8 +150,6 @@ interface StaticResourceOptions {
|
|
|
158
150
|
* @param options
|
|
159
151
|
*/
|
|
160
152
|
export declare const staticResourceCache: ({ serwist, cacheName, matchCallback, plugins, warmCache }: StaticResourceOptions) => void;
|
|
161
|
-
//#endregion
|
|
162
|
-
//#region src/warmStrategyCache.d.ts
|
|
163
153
|
interface WarmStrategyCacheOptions {
|
|
164
154
|
/**
|
|
165
155
|
* Paths to warm the strategy's cache with.
|
|
@@ -174,6 +164,5 @@ interface WarmStrategyCacheOptions {
|
|
|
174
164
|
* @param options
|
|
175
165
|
*/
|
|
176
166
|
export declare const warmStrategyCache: (options: WarmStrategyCacheOptions) => void;
|
|
177
|
-
//#endregion
|
|
178
167
|
export type { GoogleFontCacheOptions, ImageCacheOptions, OfflineFallbackOptions, PageCacheOptions, StaticResourceOptions, WarmStrategyCacheOptions };
|
|
179
168
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/googleFontsCache.ts","../src/imageCache.ts","../src/offlineFallback.ts","../src/pageCache.ts","../src/staticResourceCache.ts","../src/warmStrategyCache.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/googleFontsCache.ts","../src/imageCache.ts","../src/offlineFallback.ts","../src/pageCache.ts","../src/staticResourceCache.ts","../src/warmStrategyCache.ts"],"mappings":";UASiB;;;;EAIf,SAAS;;;;EAIT;;;;EAIA;;;;EAIA;;;;;;;qBAQW,qBAAgB,SAAA,aAAA,eAAA,cAK1B;UC1Bc;;;;EAIf,SAAS;;;;EAIT;;;;EAIA,gBAAgB;;;;EAIhB;;;;EAIA;;;;EAIA,UAAU;;;;EAIV;;;;;;;qBAQW,eAAU,SAAA,WAAA,eAAA,eAAA,YAAA,SAAA,aAQpB;UC9Cc;;;;EAIf,SAAS;;;;EAIT;;;;EAIA;;;;EAIA;;;;;;;;qBAYW,oBAAe,SAAA,cAAA,eAAA,gBAA6E;UC1BxF;;;;EAIf,SAAS;;;;EAIT;;;;EAIA,gBAAgB;;;;;;EAMhB;;;;EAIA,UAAU;;;;EAIV;;;;;;;qBAQW,cAAS,SAAA,WAAA,eAAA,uBAAA,SAAA,aAOnB;UCzCc;;;;EAIf,SAAS;;;;;;EAMT;;;;;;EAMA,gBAAgB;;;;EAIhB,UAAU;;;;EAIV;;;;;;;qBAQW,wBAAmB,SAAA,WAAA,eAAA,SAAA,aAO7B;UCjDc;;;;EAIf;;;;EAIA,UAAU;;;;;qBASC,oBAAiB,SAAa"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CacheFirst, CacheableResponsePlugin, ExpirationPlugin, NetworkFirst, StaleWhileRevalidate } from "serwist";
|
|
2
|
-
|
|
2
|
+
// src/googleFontsCache.ts
|
|
3
3
|
/**
|
|
4
4
|
* An implementation of the [Google fonts](https://developers.google.com/web/tools/workbox/guides/common-recipes#google_fonts) caching recipe.
|
|
5
5
|
*
|
|
@@ -15,8 +15,7 @@ const googleFontsCache = ({ serwist, cachePrefix = "google-fonts", maxAgeSeconds
|
|
|
15
15
|
})]
|
|
16
16
|
}));
|
|
17
17
|
};
|
|
18
|
-
|
|
19
|
-
//#region src/warmStrategyCache.ts
|
|
18
|
+
// src/warmStrategyCache.ts
|
|
20
19
|
/**
|
|
21
20
|
* @param options
|
|
22
21
|
*/
|
|
@@ -29,8 +28,7 @@ const warmStrategyCache = (options) => {
|
|
|
29
28
|
event.waitUntil(Promise.all(done));
|
|
30
29
|
});
|
|
31
30
|
};
|
|
32
|
-
|
|
33
|
-
//#region src/imageCache.ts
|
|
31
|
+
// src/imageCache.ts
|
|
34
32
|
/**
|
|
35
33
|
* An implementation of the [image caching recipe](https://developers.google.com/web/tools/workbox/guides/common-recipes#caching_images).
|
|
36
34
|
*
|
|
@@ -52,8 +50,7 @@ const imageCache = ({ serwist, cacheName = "images", matchCallback = ({ request
|
|
|
52
50
|
strategy
|
|
53
51
|
});
|
|
54
52
|
};
|
|
55
|
-
|
|
56
|
-
//#region src/offlineFallback.ts
|
|
53
|
+
// src/offlineFallback.ts
|
|
57
54
|
/**
|
|
58
55
|
* An implementation of the [comprehensive fallbacks recipe](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#comprehensive_fallbacks).
|
|
59
56
|
* Be sure to include the fallbacks in your precache injection.
|
|
@@ -77,8 +74,7 @@ const offlineFallback = ({ serwist, pageFallback = "offline.html", imageFallback
|
|
|
77
74
|
};
|
|
78
75
|
serwist.setCatchHandler(handler);
|
|
79
76
|
};
|
|
80
|
-
|
|
81
|
-
//#region src/pageCache.ts
|
|
77
|
+
// src/pageCache.ts
|
|
82
78
|
/**
|
|
83
79
|
* An implementation of a page caching recipe with a network timeout.
|
|
84
80
|
*
|
|
@@ -97,8 +93,7 @@ const pageCache = ({ serwist, cacheName = "pages", matchCallback = ({ request })
|
|
|
97
93
|
strategy
|
|
98
94
|
});
|
|
99
95
|
};
|
|
100
|
-
|
|
101
|
-
//#region src/staticResourceCache.ts
|
|
96
|
+
// src/staticResourceCache.ts
|
|
102
97
|
/**
|
|
103
98
|
* An implementation of the [CSS and JavaScript files recipe](https://developers.google.com/web/tools/workbox/guides/common-recipes#cache_css_and_javascript_files).
|
|
104
99
|
*
|
|
@@ -116,7 +111,6 @@ const staticResourceCache = ({ serwist, cacheName = "static-resources", matchCal
|
|
|
116
111
|
strategy
|
|
117
112
|
});
|
|
118
113
|
};
|
|
119
|
-
//#endregion
|
|
120
114
|
export { googleFontsCache, imageCache, offlineFallback, pageCache, staticResourceCache, warmStrategyCache };
|
|
121
115
|
|
|
122
116
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/googleFontsCache.ts","../src/warmStrategyCache.ts","../src/imageCache.ts","../src/offlineFallback.ts","../src/pageCache.ts","../src/staticResourceCache.ts"],"sourcesContent":["/*\n Copyright 2020 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { CacheableResponsePlugin, CacheFirst, ExpirationPlugin, type Serwist, StaleWhileRevalidate } from \"serwist\";\n\nexport interface GoogleFontCacheOptions {\n /**\n * A {@linkcode Serwist} instance.\n */\n serwist: Serwist;\n /**\n * Cache prefix for caching stylesheets and webfonts. Defaults to google-fonts.\n */\n cachePrefix?: string;\n /**\n * Maximum age, in seconds, that font entries will be cached for. Defaults to 1 year.\n */\n maxAgeSeconds?: number;\n /**\n * Maximum number of fonts that will be cached. Defaults to 30.\n */\n maxEntries?: number;\n}\n\n/**\n * An implementation of the [Google fonts](https://developers.google.com/web/tools/workbox/guides/common-recipes#google_fonts) caching recipe.\n *\n * @param options\n */\nexport const googleFontsCache = ({\n serwist,\n cachePrefix = \"google-fonts\",\n maxAgeSeconds = 60 * 60 * 24 * 365,\n maxEntries = 30,\n}: GoogleFontCacheOptions): void => {\n // Cache the Google Fonts stylesheets with a stale-while-revalidate strategy.\n serwist.registerCapture(\n ({ url }) => url.origin === \"https://fonts.googleapis.com\",\n new StaleWhileRevalidate({\n cacheName: `${cachePrefix}-stylesheets`,\n }),\n );\n\n // Cache the underlying font files with a cache-first strategy for 1 year.\n serwist.registerCapture(\n ({ url }) => url.origin === \"https://fonts.gstatic.com\",\n new CacheFirst({\n cacheName: `${cachePrefix}-webfonts`,\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxAgeSeconds,\n maxEntries,\n }),\n ],\n }),\n );\n};\n","import type { Strategy } from \"serwist\";\n\nexport interface WarmStrategyCacheOptions {\n /**\n * Paths to warm the strategy's cache with.\n */\n urls: string[];\n /**\n * Strategy to use.\n */\n strategy: Strategy;\n}\n\n// Give TypeScript the correct global.\ndeclare let self: ServiceWorkerGlobalScope;\n\n/**\n * @param options\n */\nexport const warmStrategyCache = (options: WarmStrategyCacheOptions): void => {\n self.addEventListener(\"install\", (event) => {\n const done = options.urls.map(\n (path) =>\n options.strategy.handleAll({\n event,\n request: new Request(path),\n })[1],\n );\n\n event.waitUntil(Promise.all(done));\n });\n};\n","/*\n Copyright 2020 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport type { RouteMatchCallback, RouteMatchCallbackOptions, SerwistPlugin } from \"serwist\";\nimport { CacheableResponsePlugin, CacheFirst, ExpirationPlugin, type Serwist } from \"serwist\";\nimport { warmStrategyCache } from \"./warmStrategyCache.js\";\n\nexport interface ImageCacheOptions {\n /**\n * A {@linkcode Serwist} instance.\n */\n serwist: Serwist;\n /**\n * Name for cache. Defaults to images.\n */\n cacheName?: string;\n /**\n * Serwist callback function to call to match to. Defaults to request.destination === 'image'.\n */\n matchCallback?: RouteMatchCallback;\n /**\n * Maximum age, in seconds, that image entries will be cached for. Defaults to 30 days.\n */\n maxAgeSeconds?: number;\n /**\n * Maximum number of images that will be cached. Defaults to 60.\n */\n maxEntries?: number;\n /**\n * Additional plugins to use for this recipe.\n */\n plugins?: SerwistPlugin[];\n /**\n * Paths to call to use to warm this cache.\n */\n warmCache?: string[];\n}\n\n/**\n * An implementation of the [image caching recipe](https://developers.google.com/web/tools/workbox/guides/common-recipes#caching_images).\n *\n * @param options\n */\nexport const imageCache = ({\n serwist,\n cacheName = \"images\",\n matchCallback = ({ request }: RouteMatchCallbackOptions) => request.destination === \"image\",\n maxAgeSeconds = 30 * 24 * 60 * 60,\n maxEntries = 60,\n plugins = [],\n warmCache,\n}: ImageCacheOptions): void => {\n plugins.push(\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n );\n plugins.push(\n new ExpirationPlugin({\n maxEntries,\n maxAgeSeconds,\n }),\n );\n\n const strategy = new CacheFirst({\n cacheName,\n plugins,\n });\n\n serwist.registerCapture(matchCallback, strategy);\n\n // Warms the cache\n if (warmCache) {\n warmStrategyCache({ urls: warmCache, strategy });\n }\n};\n","/*\n Copyright 2020 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport type { RouteHandler, RouteHandlerCallbackOptions, Serwist } from \"serwist\";\n\nexport interface OfflineFallbackOptions {\n /**\n * A {@linkcode Serwist} instance.\n */\n serwist: Serwist;\n /**\n * Precache name to match for page fallbacks. Defaults to offline.html.\n */\n pageFallback?: string;\n /**\n * Precache name to match for image fallbacks.\n */\n imageFallback?: string;\n /**\n * Precache name to match for font fallbacks.\n */\n fontFallback?: string;\n}\n\n// Give TypeScript the correct global.\ndeclare let self: ServiceWorkerGlobalScope;\n\n/**\n * An implementation of the [comprehensive fallbacks recipe](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#comprehensive_fallbacks). \n * Be sure to include the fallbacks in your precache injection.\n\n * @param options\n */\nexport const offlineFallback = ({ serwist, pageFallback = \"offline.html\", imageFallback, fontFallback }: OfflineFallbackOptions): void => {\n self.addEventListener(\"install\", (event) => {\n const files = [pageFallback];\n if (imageFallback) {\n files.push(imageFallback);\n }\n if (fontFallback) {\n files.push(fontFallback);\n }\n\n event.waitUntil(self.caches.open(\"serwist-offline-fallbacks\").then((cache) => cache.addAll(files)));\n });\n\n const handler: RouteHandler = async (options: RouteHandlerCallbackOptions) => {\n const dest = options.request.destination;\n const cache = await self.caches.open(\"serwist-offline-fallbacks\");\n\n if (dest === \"document\") {\n const match = (await serwist.matchPrecache(pageFallback)) || (await cache.match(pageFallback));\n return match || Response.error();\n }\n\n if (dest === \"image\" && imageFallback !== undefined) {\n const match = (await serwist.matchPrecache(imageFallback)) || (await cache.match(imageFallback));\n return match || Response.error();\n }\n\n if (dest === \"font\" && fontFallback !== undefined) {\n const match = (await serwist.matchPrecache(fontFallback)) || (await cache.match(fontFallback));\n return match || Response.error();\n }\n\n return Response.error();\n };\n\n serwist.setCatchHandler(handler);\n};\n","/*\n Copyright 2020 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport type { RouteMatchCallback, RouteMatchCallbackOptions, SerwistPlugin } from \"serwist\";\nimport { CacheableResponsePlugin, NetworkFirst, type Serwist } from \"serwist\";\nimport { warmStrategyCache } from \"./warmStrategyCache.js\";\n\nexport interface PageCacheOptions {\n /**\n * A {@linkcode Serwist} instance.\n */\n serwist: Serwist;\n /**\n * Name for cache. Defaults to pages.\n */\n cacheName?: string;\n /**\n * Serwist callback function to call to match to. Defaults to request.mode === 'navigate'.\n */\n matchCallback?: RouteMatchCallback;\n /**\n * Maximum amount of time, in seconds, to wait on the network before falling back to cache.\n *\n * @default 3\n */\n networkTimeoutSeconds?: number;\n /**\n * Additional plugins to use for this recipe.\n */\n plugins?: SerwistPlugin[];\n /**\n * Paths to call to use to warm this cache\n */\n warmCache?: string[];\n}\n\n/**\n * An implementation of a page caching recipe with a network timeout.\n *\n * @param options\n */\nexport const pageCache = ({\n serwist,\n cacheName = \"pages\",\n matchCallback = ({ request }: RouteMatchCallbackOptions) => request.mode === \"navigate\",\n networkTimeoutSeconds = 3,\n plugins = [],\n warmCache,\n}: PageCacheOptions): void => {\n plugins.push(\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n );\n\n const strategy = new NetworkFirst({\n networkTimeoutSeconds,\n cacheName,\n plugins,\n });\n\n // Registers the route\n serwist.registerCapture(matchCallback, strategy);\n\n // Warms the cache\n if (warmCache) {\n warmStrategyCache({ urls: warmCache, strategy });\n }\n};\n","/*\n Copyright 2020 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport type { RouteMatchCallback, RouteMatchCallbackOptions, SerwistPlugin } from \"serwist\";\nimport { CacheableResponsePlugin, type Serwist, StaleWhileRevalidate } from \"serwist\";\nimport { warmStrategyCache } from \"./warmStrategyCache.js\";\n\nexport interface StaticResourceOptions {\n /**\n * A {@linkcode Serwist} instance.\n */\n serwist: Serwist;\n /**\n * Name for cache.\n *\n * @default \"static-resources\"\n */\n cacheName?: string;\n /**\n * Serwist callback function to call to match to.\n *\n * @default request.destination === 'style' || request.destination === 'script' || request.destination === 'worker'\n */\n matchCallback?: RouteMatchCallback;\n /**\n * Additional plugins to use for this recipe.\n */\n plugins?: SerwistPlugin[];\n /**\n * Paths to call to use to warm this cache.\n */\n warmCache?: string[];\n}\n\n/**\n * An implementation of the [CSS and JavaScript files recipe](https://developers.google.com/web/tools/workbox/guides/common-recipes#cache_css_and_javascript_files).\n *\n * @param options\n */\nexport const staticResourceCache = ({\n serwist,\n cacheName = \"static-resources\",\n matchCallback = ({ request }: RouteMatchCallbackOptions) =>\n request.destination === \"style\" || request.destination === \"script\" || request.destination === \"worker\",\n plugins = [],\n warmCache,\n}: StaticResourceOptions): void => {\n plugins.push(\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n );\n\n const strategy = new StaleWhileRevalidate({\n cacheName,\n plugins,\n });\n\n serwist.registerCapture(matchCallback, strategy);\n\n // Warms the cache\n if (warmCache) {\n warmStrategyCache({ ur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W,QAAQ,gBAAgB,YAAY,QAAQ,gBAAgB,UACjG,UAAU,CAAC,GACX,gBACiC;CACjC,QAAQ,KACN,IAAI,wBAAwB,EAC1B,UAAU,CAAC,GAAG,GAAG,EACnB,CAAC,CACH;CAEA,MAAM,WAAW,IAAI,qBAAqB;EACxC;EACA;CACF,CAAC;CAED,QAAQ,gBAAgB,eAAe,QAAQ;CAG/C,IAAI,WACF,kBAAkB;EAAE,MAAM;EAAW;CAAS,CAAC;AAEnD"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/googleFontsCache.ts","../src/warmStrategyCache.ts","../src/imageCache.ts","../src/offlineFallback.ts","../src/pageCache.ts","../src/staticResourceCache.ts"],"sourcesContent":["/*\n Copyright 2020 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { CacheableResponsePlugin, CacheFirst, ExpirationPlugin, type Serwist, StaleWhileRevalidate } from \"serwist\";\n\nexport interface GoogleFontCacheOptions {\n /**\n * A {@linkcode Serwist} instance.\n */\n serwist: Serwist;\n /**\n * Cache prefix for caching stylesheets and webfonts. Defaults to google-fonts.\n */\n cachePrefix?: string;\n /**\n * Maximum age, in seconds, that font entries will be cached for. Defaults to 1 year.\n */\n maxAgeSeconds?: number;\n /**\n * Maximum number of fonts that will be cached. Defaults to 30.\n */\n maxEntries?: number;\n}\n\n/**\n * An implementation of the [Google fonts](https://developers.google.com/web/tools/workbox/guides/common-recipes#google_fonts) caching recipe.\n *\n * @param options\n */\nexport const googleFontsCache = ({\n serwist,\n cachePrefix = \"google-fonts\",\n maxAgeSeconds = 60 * 60 * 24 * 365,\n maxEntries = 30,\n}: GoogleFontCacheOptions): void => {\n // Cache the Google Fonts stylesheets with a stale-while-revalidate strategy.\n serwist.registerCapture(\n ({ url }) => url.origin === \"https://fonts.googleapis.com\",\n new StaleWhileRevalidate({\n cacheName: `${cachePrefix}-stylesheets`,\n }),\n );\n\n // Cache the underlying font files with a cache-first strategy for 1 year.\n serwist.registerCapture(\n ({ url }) => url.origin === \"https://fonts.gstatic.com\",\n new CacheFirst({\n cacheName: `${cachePrefix}-webfonts`,\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxAgeSeconds,\n maxEntries,\n }),\n ],\n }),\n );\n};\n","import type { Strategy } from \"serwist\";\n\nexport interface WarmStrategyCacheOptions {\n /**\n * Paths to warm the strategy's cache with.\n */\n urls: string[];\n /**\n * Strategy to use.\n */\n strategy: Strategy;\n}\n\n// Give TypeScript the correct global.\ndeclare let self: ServiceWorkerGlobalScope;\n\n/**\n * @param options\n */\nexport const warmStrategyCache = (options: WarmStrategyCacheOptions): void => {\n self.addEventListener(\"install\", (event) => {\n const done = options.urls.map(\n (path) =>\n options.strategy.handleAll({\n event,\n request: new Request(path),\n })[1],\n );\n\n event.waitUntil(Promise.all(done));\n });\n};\n","/*\n Copyright 2020 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport type { RouteMatchCallback, RouteMatchCallbackOptions, SerwistPlugin } from \"serwist\";\nimport { CacheableResponsePlugin, CacheFirst, ExpirationPlugin, type Serwist } from \"serwist\";\nimport { warmStrategyCache } from \"./warmStrategyCache.js\";\n\nexport interface ImageCacheOptions {\n /**\n * A {@linkcode Serwist} instance.\n */\n serwist: Serwist;\n /**\n * Name for cache. Defaults to images.\n */\n cacheName?: string;\n /**\n * Serwist callback function to call to match to. Defaults to request.destination === 'image'.\n */\n matchCallback?: RouteMatchCallback;\n /**\n * Maximum age, in seconds, that image entries will be cached for. Defaults to 30 days.\n */\n maxAgeSeconds?: number;\n /**\n * Maximum number of images that will be cached. Defaults to 60.\n */\n maxEntries?: number;\n /**\n * Additional plugins to use for this recipe.\n */\n plugins?: SerwistPlugin[];\n /**\n * Paths to call to use to warm this cache.\n */\n warmCache?: string[];\n}\n\n/**\n * An implementation of the [image caching recipe](https://developers.google.com/web/tools/workbox/guides/common-recipes#caching_images).\n *\n * @param options\n */\nexport const imageCache = ({\n serwist,\n cacheName = \"images\",\n matchCallback = ({ request }: RouteMatchCallbackOptions) => request.destination === \"image\",\n maxAgeSeconds = 30 * 24 * 60 * 60,\n maxEntries = 60,\n plugins = [],\n warmCache,\n}: ImageCacheOptions): void => {\n plugins.push(\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n );\n plugins.push(\n new ExpirationPlugin({\n maxEntries,\n maxAgeSeconds,\n }),\n );\n\n const strategy = new CacheFirst({\n cacheName,\n plugins,\n });\n\n serwist.registerCapture(matchCallback, strategy);\n\n // Warms the cache\n if (warmCache) {\n warmStrategyCache({ urls: warmCache, strategy });\n }\n};\n","/*\n Copyright 2020 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport type { RouteHandler, RouteHandlerCallbackOptions, Serwist } from \"serwist\";\n\nexport interface OfflineFallbackOptions {\n /**\n * A {@linkcode Serwist} instance.\n */\n serwist: Serwist;\n /**\n * Precache name to match for page fallbacks. Defaults to offline.html.\n */\n pageFallback?: string;\n /**\n * Precache name to match for image fallbacks.\n */\n imageFallback?: string;\n /**\n * Precache name to match for font fallbacks.\n */\n fontFallback?: string;\n}\n\n// Give TypeScript the correct global.\ndeclare let self: ServiceWorkerGlobalScope;\n\n/**\n * An implementation of the [comprehensive fallbacks recipe](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#comprehensive_fallbacks). \n * Be sure to include the fallbacks in your precache injection.\n\n * @param options\n */\nexport const offlineFallback = ({ serwist, pageFallback = \"offline.html\", imageFallback, fontFallback }: OfflineFallbackOptions): void => {\n self.addEventListener(\"install\", (event) => {\n const files = [pageFallback];\n if (imageFallback) {\n files.push(imageFallback);\n }\n if (fontFallback) {\n files.push(fontFallback);\n }\n\n event.waitUntil(self.caches.open(\"serwist-offline-fallbacks\").then((cache) => cache.addAll(files)));\n });\n\n const handler: RouteHandler = async (options: RouteHandlerCallbackOptions) => {\n const dest = options.request.destination;\n const cache = await self.caches.open(\"serwist-offline-fallbacks\");\n\n if (dest === \"document\") {\n const match = (await serwist.matchPrecache(pageFallback)) || (await cache.match(pageFallback));\n return match || Response.error();\n }\n\n if (dest === \"image\" && imageFallback !== undefined) {\n const match = (await serwist.matchPrecache(imageFallback)) || (await cache.match(imageFallback));\n return match || Response.error();\n }\n\n if (dest === \"font\" && fontFallback !== undefined) {\n const match = (await serwist.matchPrecache(fontFallback)) || (await cache.match(fontFallback));\n return match || Response.error();\n }\n\n return Response.error();\n };\n\n serwist.setCatchHandler(handler);\n};\n","/*\n Copyright 2020 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport type { RouteMatchCallback, RouteMatchCallbackOptions, SerwistPlugin } from \"serwist\";\nimport { CacheableResponsePlugin, NetworkFirst, type Serwist } from \"serwist\";\nimport { warmStrategyCache } from \"./warmStrategyCache.js\";\n\nexport interface PageCacheOptions {\n /**\n * A {@linkcode Serwist} instance.\n */\n serwist: Serwist;\n /**\n * Name for cache. Defaults to pages.\n */\n cacheName?: string;\n /**\n * Serwist callback function to call to match to. Defaults to request.mode === 'navigate'.\n */\n matchCallback?: RouteMatchCallback;\n /**\n * Maximum amount of time, in seconds, to wait on the network before falling back to cache.\n *\n * @default 3\n */\n networkTimeoutSeconds?: number;\n /**\n * Additional plugins to use for this recipe.\n */\n plugins?: SerwistPlugin[];\n /**\n * Paths to call to use to warm this cache\n */\n warmCache?: string[];\n}\n\n/**\n * An implementation of a page caching recipe with a network timeout.\n *\n * @param options\n */\nexport const pageCache = ({\n serwist,\n cacheName = \"pages\",\n matchCallback = ({ request }: RouteMatchCallbackOptions) => request.mode === \"navigate\",\n networkTimeoutSeconds = 3,\n plugins = [],\n warmCache,\n}: PageCacheOptions): void => {\n plugins.push(\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n );\n\n const strategy = new NetworkFirst({\n networkTimeoutSeconds,\n cacheName,\n plugins,\n });\n\n // Registers the route\n serwist.registerCapture(matchCallback, strategy);\n\n // Warms the cache\n if (warmCache) {\n warmStrategyCache({ urls: warmCache, strategy });\n }\n};\n","/*\n Copyright 2020 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport type { RouteMatchCallback, RouteMatchCallbackOptions, SerwistPlugin } from \"serwist\";\nimport { CacheableResponsePlugin, type Serwist, StaleWhileRevalidate } from \"serwist\";\nimport { warmStrategyCache } from \"./warmStrategyCache.js\";\n\nexport interface StaticResourceOptions {\n /**\n * A {@linkcode Serwist} instance.\n */\n serwist: Serwist;\n /**\n * Name for cache.\n *\n * @default \"static-resources\"\n */\n cacheName?: string;\n /**\n * Serwist callback function to call to match to.\n *\n * @default request.destination === 'style' || request.destination === 'script' || request.destination === 'worker'\n */\n matchCallback?: RouteMatchCallback;\n /**\n * Additional plugins to use for this recipe.\n */\n plugins?: SerwistPlugin[];\n /**\n * Paths to call to use to warm this cache.\n */\n warmCache?: string[];\n}\n\n/**\n * An implementation of the [CSS and JavaScript files recipe](https://developers.google.com/web/tools/workbox/guides/common-recipes#cache_css_and_javascript_files).\n *\n * @param options\n */\nexport const staticResourceCache = ({\n serwist,\n cacheName = \"static-resources\",\n matchCallback = ({ request }: RouteMatchCallbackOptions) =>\n request.destination === \"style\" || request.destination === \"script\" || request.destination === \"worker\",\n plugins = [],\n warmCache,\n}: StaticResourceOptions): void => {\n plugins.push(\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n );\n\n const strategy = new StaleWhileRevalidate({\n cacheName,\n plugins,\n });\n\n serwist.registerCapture(matchCallback, strategy);\n\n // Warms the cache\n if (warmCache) {\n warmStrategyCache({ urls: warmCache, strategy });\n }\n};\n"],"mappings":";;;;;;;AAiCA,MAAa,oBAAoB,EAC/B,SACA,cAAc,gBACd,gBAAgB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wB,EAC1B,UAAU,CAAC,GAAG,GAAG,EACnB,CAAC,CACH;CAEA,MAAM,WAAW,IAAI,qBAAqB;EACxC;EACA;CACF,CAAC;CAED,QAAQ,gBAAgB,eAAe,QAAQ;CAG/C,IAAI,WACF,kBAAkB;EAAE,MAAM;EAAW;CAAS,CAAC;AAEnD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/recipes",
|
|
3
|
-
"version": "9.5.
|
|
3
|
+
"version": "9.5.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A service worker helper library to manage common request and caching patterns",
|
|
6
6
|
"files": [
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"./package.json": "./package.json"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"serwist": "9.5.
|
|
39
|
+
"serwist": "9.5.15"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"tsdown": "0.23.0",
|