@serwist/recipes 9.0.0-preview.0 → 9.0.0-preview.1
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.js +6 -35
- package/package.json +8 -8
package/dist/index.js
CHANGED
@@ -4,20 +4,14 @@ import { registerRoute, setCatchHandler } from '@serwist/routing';
|
|
4
4
|
import { StaleWhileRevalidate, CacheFirst, NetworkFirst } from '@serwist/strategies';
|
5
5
|
import { matchPrecache } from '@serwist/precaching';
|
6
6
|
|
7
|
-
|
8
|
-
* An implementation of the [Google fonts](https://developers.google.com/web/tools/workbox/guides/common-recipes#google_fonts) caching recipe.
|
9
|
-
*
|
10
|
-
* @param options
|
11
|
-
*/ function googleFontsCache(options = {}) {
|
7
|
+
function googleFontsCache(options = {}) {
|
12
8
|
const sheetCacheName = `${options.cachePrefix || "google-fonts"}-stylesheets`;
|
13
9
|
const fontCacheName = `${options.cachePrefix || "google-fonts"}-webfonts`;
|
14
10
|
const maxAgeSeconds = options.maxAgeSeconds || 60 * 60 * 24 * 365;
|
15
11
|
const maxEntries = options.maxEntries || 30;
|
16
|
-
// Cache the Google Fonts stylesheets with a stale-while-revalidate strategy.
|
17
12
|
registerRoute(({ url })=>url.origin === "https://fonts.googleapis.com", new StaleWhileRevalidate({
|
18
13
|
cacheName: sheetCacheName
|
19
14
|
}));
|
20
|
-
// Cache the underlying font files with a cache-first strategy for 1 year.
|
21
15
|
registerRoute(({ url })=>url.origin === "https://fonts.gstatic.com", new CacheFirst({
|
22
16
|
cacheName: fontCacheName,
|
23
17
|
plugins: [
|
@@ -35,9 +29,7 @@ import { matchPrecache } from '@serwist/precaching';
|
|
35
29
|
}));
|
36
30
|
}
|
37
31
|
|
38
|
-
|
39
|
-
* @param options
|
40
|
-
*/ function warmStrategyCache(options) {
|
32
|
+
function warmStrategyCache(options) {
|
41
33
|
self.addEventListener("install", (event)=>{
|
42
34
|
const done = options.urls.map((path)=>options.strategy.handleAll({
|
43
35
|
event,
|
@@ -47,11 +39,7 @@ import { matchPrecache } from '@serwist/precaching';
|
|
47
39
|
});
|
48
40
|
}
|
49
41
|
|
50
|
-
|
51
|
-
* An implementation of the [image caching recipe](https://developers.google.com/web/tools/workbox/guides/common-recipes#caching_images).
|
52
|
-
*
|
53
|
-
* @param options
|
54
|
-
*/ function imageCache(options = {}) {
|
42
|
+
function imageCache(options = {}) {
|
55
43
|
const defaultMatchCallback = ({ request })=>request.destination === "image";
|
56
44
|
const cacheName = options.cacheName || "images";
|
57
45
|
const matchCallback = options.matchCallback || defaultMatchCallback;
|
@@ -73,7 +61,6 @@ import { matchPrecache } from '@serwist/precaching';
|
|
73
61
|
plugins
|
74
62
|
});
|
75
63
|
registerRoute(matchCallback, strategy);
|
76
|
-
// Warms the cache
|
77
64
|
if (options.warmCache) {
|
78
65
|
warmStrategyCache({
|
79
66
|
urls: options.warmCache,
|
@@ -82,12 +69,7 @@ import { matchPrecache } from '@serwist/precaching';
|
|
82
69
|
}
|
83
70
|
}
|
84
71
|
|
85
|
-
|
86
|
-
* An implementation of the [comprehensive fallbacks recipe](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#comprehensive_fallbacks).
|
87
|
-
* Be sure to include the fallbacks in your precache injection.
|
88
|
-
|
89
|
-
* @param options
|
90
|
-
*/ function offlineFallback(options = {}) {
|
72
|
+
function offlineFallback(options = {}) {
|
91
73
|
const pageFallback = options.pageFallback || "offline.html";
|
92
74
|
const imageFallback = options.imageFallback || false;
|
93
75
|
const fontFallback = options.fontFallback || false;
|
@@ -123,11 +105,7 @@ import { matchPrecache } from '@serwist/precaching';
|
|
123
105
|
setCatchHandler(handler);
|
124
106
|
}
|
125
107
|
|
126
|
-
|
127
|
-
* An implementation of a page caching recipe with a network timeout.
|
128
|
-
*
|
129
|
-
* @param options
|
130
|
-
*/ function pageCache(options = {}) {
|
108
|
+
function pageCache(options = {}) {
|
131
109
|
const defaultMatchCallback = ({ request })=>request.mode === "navigate";
|
132
110
|
const cacheName = options.cacheName || "pages";
|
133
111
|
const matchCallback = options.matchCallback || defaultMatchCallback;
|
@@ -144,9 +122,7 @@ import { matchPrecache } from '@serwist/precaching';
|
|
144
122
|
cacheName,
|
145
123
|
plugins
|
146
124
|
});
|
147
|
-
// Registers the route
|
148
125
|
registerRoute(matchCallback, strategy);
|
149
|
-
// Warms the cache
|
150
126
|
if (options.warmCache) {
|
151
127
|
warmStrategyCache({
|
152
128
|
urls: options.warmCache,
|
@@ -155,11 +131,7 @@ import { matchPrecache } from '@serwist/precaching';
|
|
155
131
|
}
|
156
132
|
}
|
157
133
|
|
158
|
-
|
159
|
-
* An implementation of the [CSS and JavaScript files recipe](https://developers.google.com/web/tools/workbox/guides/common-recipes#cache_css_and_javascript_files).
|
160
|
-
*
|
161
|
-
* @param options
|
162
|
-
*/ function staticResourceCache(options = {}) {
|
134
|
+
function staticResourceCache(options = {}) {
|
163
135
|
const defaultMatchCallback = ({ request })=>request.destination === "style" || request.destination === "script" || request.destination === "worker";
|
164
136
|
const cacheName = options.cacheName || "static-resources";
|
165
137
|
const matchCallback = options.matchCallback || defaultMatchCallback;
|
@@ -175,7 +147,6 @@ import { matchPrecache } from '@serwist/precaching';
|
|
175
147
|
plugins
|
176
148
|
});
|
177
149
|
registerRoute(matchCallback, strategy);
|
178
|
-
// Warms the cache
|
179
150
|
if (options.warmCache) {
|
180
151
|
warmStrategyCache({
|
181
152
|
urls: options.warmCache,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@serwist/recipes",
|
3
|
-
"version": "9.0.0-preview.
|
3
|
+
"version": "9.0.0-preview.1",
|
4
4
|
"type": "module",
|
5
5
|
"description": "A service worker helper library to manage common request and caching patterns",
|
6
6
|
"files": [
|
@@ -30,17 +30,17 @@
|
|
30
30
|
"./package.json": "./package.json"
|
31
31
|
},
|
32
32
|
"dependencies": {
|
33
|
-
"@serwist/cacheable-response": "9.0.0-preview.
|
34
|
-
"@serwist/core": "9.0.0-preview.
|
35
|
-
"@serwist/expiration": "9.0.0-preview.
|
36
|
-
"@serwist/precaching": "9.0.0-preview.
|
37
|
-
"@serwist/routing": "9.0.0-preview.
|
38
|
-
"@serwist/strategies": "9.0.0-preview.
|
33
|
+
"@serwist/cacheable-response": "9.0.0-preview.1",
|
34
|
+
"@serwist/core": "9.0.0-preview.1",
|
35
|
+
"@serwist/expiration": "9.0.0-preview.1",
|
36
|
+
"@serwist/precaching": "9.0.0-preview.1",
|
37
|
+
"@serwist/routing": "9.0.0-preview.1",
|
38
|
+
"@serwist/strategies": "9.0.0-preview.1"
|
39
39
|
},
|
40
40
|
"devDependencies": {
|
41
41
|
"rollup": "4.9.6",
|
42
42
|
"typescript": "5.4.0-dev.20240203",
|
43
|
-
"@serwist/constants": "9.0.0-preview.
|
43
|
+
"@serwist/constants": "9.0.0-preview.1"
|
44
44
|
},
|
45
45
|
"peerDependencies": {
|
46
46
|
"typescript": ">=5.0.0"
|