@serwist/next 9.0.0-preview.2 → 9.0.0-preview.3
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.worker.d.ts +2 -3
- package/dist/index.worker.d.ts.map +1 -1
- package/dist/index.worker.js +161 -155
- package/dist/worker/constants.d.ts +6 -0
- package/dist/worker/constants.d.ts.map +1 -0
- package/dist/worker/defaultCache.d.ts +14 -2
- package/dist/worker/defaultCache.d.ts.map +1 -1
- package/package.json +12 -9
- package/src/index.worker.ts +2 -3
- package/src/worker/constants.ts +5 -0
- package/src/worker/defaultCache.ts +160 -137
- package/dist/worker/definePageRuntimeCaching.d.ts +0 -16
- package/dist/worker/definePageRuntimeCaching.d.ts.map +0 -1
- package/src/worker/definePageRuntimeCaching.ts +0 -36
package/dist/index.worker.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
+
import { PAGES_CACHE_NAME } from "./worker/constants.js";
|
|
1
2
|
import { defaultCache } from "./worker/defaultCache.js";
|
|
2
|
-
|
|
3
|
-
export { defaultCache, definePageRuntimeCaching };
|
|
4
|
-
export type { DefinePageRuntimeCachingOptions, PageRuntimeCaching };
|
|
3
|
+
export { defaultCache, PAGES_CACHE_NAME };
|
|
5
4
|
//# sourceMappingURL=index.worker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.worker.d.ts","sourceRoot":"","sources":["../src/index.worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.worker.d.ts","sourceRoot":"","sources":["../src/index.worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,CAAC"}
|
package/dist/index.worker.js
CHANGED
|
@@ -1,160 +1,159 @@
|
|
|
1
|
-
|
|
1
|
+
import { ExpirationPlugin } from '@serwist/expiration';
|
|
2
|
+
import { RangeRequestsPlugin } from '@serwist/range-requests';
|
|
3
|
+
import { CacheFirst, StaleWhileRevalidate, NetworkFirst } from '@serwist/strategies';
|
|
2
4
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
html
|
|
8
|
-
];
|
|
9
|
-
if (pageRcs[0]) {
|
|
10
|
-
if (!pageRcs[0].options) pageRcs[0].options = {};
|
|
11
|
-
pageRcs[0].options.cacheName = "pages-rsc-prefetch";
|
|
12
|
-
}
|
|
13
|
-
if (pageRcs[1]) {
|
|
14
|
-
if (!pageRcs[1].options) pageRcs[1].options = {};
|
|
15
|
-
pageRcs[1].options.cacheName = "pages-rsc";
|
|
16
|
-
}
|
|
17
|
-
if (pageRcs[2]) {
|
|
18
|
-
if (!pageRcs[2].options) pageRcs[2].options = {};
|
|
19
|
-
pageRcs[2].options.cacheName = "pages";
|
|
20
|
-
}
|
|
21
|
-
return pageRcs.filter(nonNullable);
|
|
5
|
+
const PAGES_CACHE_NAME = {
|
|
6
|
+
rscPrefetch: "pages-rsc-prefetch",
|
|
7
|
+
rsc: "pages-rsc",
|
|
8
|
+
html: "pages"
|
|
22
9
|
};
|
|
23
10
|
|
|
24
11
|
const defaultCache = [
|
|
25
12
|
{
|
|
26
13
|
urlPattern: /^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,
|
|
27
|
-
handler:
|
|
28
|
-
options: {
|
|
14
|
+
handler: new CacheFirst({
|
|
29
15
|
cacheName: "google-fonts-webfonts",
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
16
|
+
plugins: [
|
|
17
|
+
new ExpirationPlugin({
|
|
18
|
+
maxEntries: 4,
|
|
19
|
+
maxAgeSeconds: 365 * 24 * 60 * 60
|
|
20
|
+
})
|
|
21
|
+
]
|
|
22
|
+
})
|
|
35
23
|
},
|
|
36
24
|
{
|
|
37
25
|
urlPattern: /^https:\/\/fonts\.(?:googleapis)\.com\/.*/i,
|
|
38
|
-
handler:
|
|
39
|
-
options: {
|
|
26
|
+
handler: new StaleWhileRevalidate({
|
|
40
27
|
cacheName: "google-fonts-stylesheets",
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
28
|
+
plugins: [
|
|
29
|
+
new ExpirationPlugin({
|
|
30
|
+
maxEntries: 4,
|
|
31
|
+
maxAgeSeconds: 7 * 24 * 60 * 60
|
|
32
|
+
})
|
|
33
|
+
]
|
|
34
|
+
})
|
|
46
35
|
},
|
|
47
36
|
{
|
|
48
37
|
urlPattern: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
|
|
49
|
-
handler:
|
|
50
|
-
options: {
|
|
38
|
+
handler: new StaleWhileRevalidate({
|
|
51
39
|
cacheName: "static-font-assets",
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
40
|
+
plugins: [
|
|
41
|
+
new ExpirationPlugin({
|
|
42
|
+
maxEntries: 4,
|
|
43
|
+
maxAgeSeconds: 7 * 24 * 60 * 60
|
|
44
|
+
})
|
|
45
|
+
]
|
|
46
|
+
})
|
|
57
47
|
},
|
|
58
48
|
{
|
|
59
49
|
urlPattern: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
|
|
60
|
-
handler:
|
|
61
|
-
options: {
|
|
50
|
+
handler: new StaleWhileRevalidate({
|
|
62
51
|
cacheName: "static-image-assets",
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
52
|
+
plugins: [
|
|
53
|
+
new ExpirationPlugin({
|
|
54
|
+
maxEntries: 64,
|
|
55
|
+
maxAgeSeconds: 30 * 24 * 60 * 60
|
|
56
|
+
})
|
|
57
|
+
]
|
|
58
|
+
})
|
|
68
59
|
},
|
|
69
60
|
{
|
|
70
61
|
urlPattern: /\/_next\/static.+\.js$/i,
|
|
71
|
-
handler:
|
|
72
|
-
options: {
|
|
62
|
+
handler: new CacheFirst({
|
|
73
63
|
cacheName: "next-static-js-assets",
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
64
|
+
plugins: [
|
|
65
|
+
new ExpirationPlugin({
|
|
66
|
+
maxEntries: 64,
|
|
67
|
+
maxAgeSeconds: 24 * 60 * 60
|
|
68
|
+
})
|
|
69
|
+
]
|
|
70
|
+
})
|
|
79
71
|
},
|
|
80
72
|
{
|
|
81
73
|
urlPattern: /\/_next\/image\?url=.+$/i,
|
|
82
|
-
handler:
|
|
83
|
-
options: {
|
|
74
|
+
handler: new StaleWhileRevalidate({
|
|
84
75
|
cacheName: "next-image",
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
76
|
+
plugins: [
|
|
77
|
+
new ExpirationPlugin({
|
|
78
|
+
maxEntries: 64,
|
|
79
|
+
maxAgeSeconds: 24 * 60 * 60
|
|
80
|
+
})
|
|
81
|
+
]
|
|
82
|
+
})
|
|
90
83
|
},
|
|
91
84
|
{
|
|
92
85
|
urlPattern: /\.(?:mp3|wav|ogg)$/i,
|
|
93
|
-
handler:
|
|
94
|
-
options: {
|
|
95
|
-
rangeRequests: true,
|
|
86
|
+
handler: new CacheFirst({
|
|
96
87
|
cacheName: "static-audio-assets",
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
88
|
+
plugins: [
|
|
89
|
+
new ExpirationPlugin({
|
|
90
|
+
maxEntries: 32,
|
|
91
|
+
maxAgeSeconds: 24 * 60 * 60
|
|
92
|
+
}),
|
|
93
|
+
new RangeRequestsPlugin()
|
|
94
|
+
]
|
|
95
|
+
})
|
|
102
96
|
},
|
|
103
97
|
{
|
|
104
98
|
urlPattern: /\.(?:mp4|webm)$/i,
|
|
105
|
-
handler:
|
|
106
|
-
options: {
|
|
107
|
-
rangeRequests: true,
|
|
99
|
+
handler: new CacheFirst({
|
|
108
100
|
cacheName: "static-video-assets",
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
101
|
+
plugins: [
|
|
102
|
+
new ExpirationPlugin({
|
|
103
|
+
maxEntries: 32,
|
|
104
|
+
maxAgeSeconds: 24 * 60 * 60
|
|
105
|
+
}),
|
|
106
|
+
new RangeRequestsPlugin()
|
|
107
|
+
]
|
|
108
|
+
})
|
|
114
109
|
},
|
|
115
110
|
{
|
|
116
111
|
urlPattern: /\.(?:js)$/i,
|
|
117
|
-
handler:
|
|
118
|
-
options: {
|
|
112
|
+
handler: new StaleWhileRevalidate({
|
|
119
113
|
cacheName: "static-js-assets",
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
114
|
+
plugins: [
|
|
115
|
+
new ExpirationPlugin({
|
|
116
|
+
maxEntries: 48,
|
|
117
|
+
maxAgeSeconds: 24 * 60 * 60
|
|
118
|
+
})
|
|
119
|
+
]
|
|
120
|
+
})
|
|
125
121
|
},
|
|
126
122
|
{
|
|
127
123
|
urlPattern: /\.(?:css|less)$/i,
|
|
128
|
-
handler:
|
|
129
|
-
options: {
|
|
124
|
+
handler: new StaleWhileRevalidate({
|
|
130
125
|
cacheName: "static-style-assets",
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
126
|
+
plugins: [
|
|
127
|
+
new ExpirationPlugin({
|
|
128
|
+
maxEntries: 32,
|
|
129
|
+
maxAgeSeconds: 24 * 60 * 60
|
|
130
|
+
})
|
|
131
|
+
]
|
|
132
|
+
})
|
|
136
133
|
},
|
|
137
134
|
{
|
|
138
135
|
urlPattern: /\/_next\/data\/.+\/.+\.json$/i,
|
|
139
|
-
handler:
|
|
140
|
-
options: {
|
|
136
|
+
handler: new StaleWhileRevalidate({
|
|
141
137
|
cacheName: "next-data",
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
138
|
+
plugins: [
|
|
139
|
+
new ExpirationPlugin({
|
|
140
|
+
maxEntries: 32,
|
|
141
|
+
maxAgeSeconds: 24 * 60 * 60
|
|
142
|
+
})
|
|
143
|
+
]
|
|
144
|
+
})
|
|
147
145
|
},
|
|
148
146
|
{
|
|
149
147
|
urlPattern: /\.(?:json|xml|csv)$/i,
|
|
150
|
-
handler:
|
|
151
|
-
options: {
|
|
148
|
+
handler: new NetworkFirst({
|
|
152
149
|
cacheName: "static-data-assets",
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
150
|
+
plugins: [
|
|
151
|
+
new ExpirationPlugin({
|
|
152
|
+
maxEntries: 32,
|
|
153
|
+
maxAgeSeconds: 24 * 60 * 60
|
|
154
|
+
})
|
|
155
|
+
]
|
|
156
|
+
})
|
|
158
157
|
},
|
|
159
158
|
{
|
|
160
159
|
urlPattern: ({ sameOrigin, url: { pathname } })=>{
|
|
@@ -166,72 +165,79 @@ const defaultCache = [
|
|
|
166
165
|
}
|
|
167
166
|
return false;
|
|
168
167
|
},
|
|
169
|
-
handler: "NetworkFirst",
|
|
170
168
|
method: "GET",
|
|
171
|
-
|
|
169
|
+
handler: new NetworkFirst({
|
|
172
170
|
cacheName: "apis",
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
171
|
+
plugins: [
|
|
172
|
+
new ExpirationPlugin({
|
|
173
|
+
maxEntries: 16,
|
|
174
|
+
maxAgeSeconds: 24 * 60 * 60
|
|
175
|
+
})
|
|
176
|
+
],
|
|
177
177
|
networkTimeoutSeconds: 10
|
|
178
|
-
}
|
|
179
|
-
},
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
178
|
+
})
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
urlPattern: ({ request, url: { pathname }, sameOrigin })=>request.headers.get("RSC") === "1" && request.headers.get("Next-Router-Prefetch") === "1" && sameOrigin && !pathname.startsWith("/api/"),
|
|
182
|
+
handler: new NetworkFirst({
|
|
183
|
+
cacheName: PAGES_CACHE_NAME.rscPrefetch,
|
|
184
|
+
plugins: [
|
|
185
|
+
new ExpirationPlugin({
|
|
186
186
|
maxEntries: 32,
|
|
187
187
|
maxAgeSeconds: 24 * 60 * 60
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
188
|
+
})
|
|
189
|
+
]
|
|
190
|
+
})
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
urlPattern: ({ request, url: { pathname }, sameOrigin })=>request.headers.get("RSC") === "1" && sameOrigin && !pathname.startsWith("/api/"),
|
|
194
|
+
handler: new NetworkFirst({
|
|
195
|
+
cacheName: PAGES_CACHE_NAME.rsc,
|
|
196
|
+
plugins: [
|
|
197
|
+
new ExpirationPlugin({
|
|
196
198
|
maxEntries: 32,
|
|
197
199
|
maxAgeSeconds: 24 * 60 * 60
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
200
|
+
})
|
|
201
|
+
]
|
|
202
|
+
})
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
urlPattern: ({ request, url: { pathname }, sameOrigin })=>request.headers.get("Content-Type")?.includes("text/html") && sameOrigin && !pathname.startsWith("/api/"),
|
|
206
|
+
handler: new NetworkFirst({
|
|
207
|
+
cacheName: PAGES_CACHE_NAME.html,
|
|
208
|
+
plugins: [
|
|
209
|
+
new ExpirationPlugin({
|
|
206
210
|
maxEntries: 32,
|
|
207
211
|
maxAgeSeconds: 24 * 60 * 60
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
+
})
|
|
213
|
+
]
|
|
214
|
+
})
|
|
215
|
+
},
|
|
212
216
|
{
|
|
213
217
|
urlPattern: ({ url: { pathname }, sameOrigin })=>sameOrigin && !pathname.startsWith("/api/"),
|
|
214
|
-
handler:
|
|
215
|
-
options: {
|
|
218
|
+
handler: new NetworkFirst({
|
|
216
219
|
cacheName: "others",
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
plugins: [
|
|
221
|
+
new ExpirationPlugin({
|
|
222
|
+
maxEntries: 32,
|
|
223
|
+
maxAgeSeconds: 24 * 60 * 60
|
|
224
|
+
})
|
|
225
|
+
]
|
|
226
|
+
})
|
|
222
227
|
},
|
|
223
228
|
{
|
|
224
229
|
urlPattern: ({ sameOrigin })=>!sameOrigin,
|
|
225
|
-
handler:
|
|
226
|
-
options: {
|
|
230
|
+
handler: new NetworkFirst({
|
|
227
231
|
cacheName: "cross-origin",
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
+
plugins: [
|
|
233
|
+
new ExpirationPlugin({
|
|
234
|
+
maxEntries: 32,
|
|
235
|
+
maxAgeSeconds: 60 * 60
|
|
236
|
+
})
|
|
237
|
+
],
|
|
232
238
|
networkTimeoutSeconds: 10
|
|
233
|
-
}
|
|
239
|
+
})
|
|
234
240
|
}
|
|
235
241
|
];
|
|
236
242
|
|
|
237
|
-
export {
|
|
243
|
+
export { PAGES_CACHE_NAME, defaultCache };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/worker/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB;;;;CAInB,CAAC"}
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare const defaultCache:
|
|
1
|
+
import { CacheFirst, NetworkFirst } from "@serwist/strategies";
|
|
2
|
+
export declare const defaultCache: ({
|
|
3
|
+
urlPattern: RegExp;
|
|
4
|
+
handler: CacheFirst;
|
|
5
|
+
method?: undefined;
|
|
6
|
+
} | {
|
|
7
|
+
urlPattern: ({ sameOrigin, url: { pathname } }: import("@serwist/core").RouteMatchCallbackOptions) => boolean;
|
|
8
|
+
method: "GET";
|
|
9
|
+
handler: NetworkFirst;
|
|
10
|
+
} | {
|
|
11
|
+
urlPattern: ({ request, url: { pathname }, sameOrigin }: import("@serwist/core").RouteMatchCallbackOptions) => boolean | undefined;
|
|
12
|
+
handler: NetworkFirst;
|
|
13
|
+
method?: undefined;
|
|
14
|
+
})[];
|
|
3
15
|
//# sourceMappingURL=defaultCache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultCache.d.ts","sourceRoot":"","sources":["../../src/worker/defaultCache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"defaultCache.d.ts","sourceRoot":"","sources":["../../src/worker/defaultCache.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAwB,MAAM,qBAAqB,CAAC;AAMrF,eAAO,MAAM,YAAY;;;;;;;;;;;;IA6OG,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/next",
|
|
3
|
-
"version": "9.0.0-preview.
|
|
3
|
+
"version": "9.0.0-preview.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A module that integrates Serwist into your Next.js application.",
|
|
6
6
|
"files": [
|
|
@@ -53,10 +53,13 @@
|
|
|
53
53
|
"chalk": "5.3.0",
|
|
54
54
|
"clean-webpack-plugin": "4.0.0",
|
|
55
55
|
"fast-glob": "3.3.2",
|
|
56
|
-
"@serwist/build": "9.0.0-preview.
|
|
57
|
-
"@serwist/core": "9.0.0-preview.
|
|
58
|
-
"@serwist/
|
|
59
|
-
"@serwist/
|
|
56
|
+
"@serwist/build": "9.0.0-preview.3",
|
|
57
|
+
"@serwist/core": "9.0.0-preview.3",
|
|
58
|
+
"@serwist/expiration": "9.0.0-preview.3",
|
|
59
|
+
"@serwist/range-requests": "9.0.0-preview.3",
|
|
60
|
+
"@serwist/strategies": "9.0.0-preview.3",
|
|
61
|
+
"@serwist/webpack-plugin": "9.0.0-preview.3",
|
|
62
|
+
"@serwist/window": "9.0.0-preview.3"
|
|
60
63
|
},
|
|
61
64
|
"devDependencies": {
|
|
62
65
|
"@types/node": "20.11.16",
|
|
@@ -67,15 +70,15 @@
|
|
|
67
70
|
"type-fest": "4.10.2",
|
|
68
71
|
"typescript": "5.4.0-dev.20240206",
|
|
69
72
|
"webpack": "5.90.1",
|
|
70
|
-
"@serwist/constants": "9.0.0-preview.
|
|
71
|
-
"@serwist/sw": "9.0.0-preview.
|
|
72
|
-
"@serwist/utils": "9.0.0-preview.
|
|
73
|
+
"@serwist/constants": "9.0.0-preview.3",
|
|
74
|
+
"@serwist/sw": "9.0.0-preview.3",
|
|
75
|
+
"@serwist/utils": "9.0.0-preview.3"
|
|
73
76
|
},
|
|
74
77
|
"peerDependencies": {
|
|
75
78
|
"next": ">=14.0.0",
|
|
76
79
|
"typescript": ">=5.0.0",
|
|
77
80
|
"webpack": ">=5.9.0",
|
|
78
|
-
"@serwist/sw": "9.0.0-preview.
|
|
81
|
+
"@serwist/sw": "9.0.0-preview.3"
|
|
79
82
|
},
|
|
80
83
|
"peerDependenciesMeta": {
|
|
81
84
|
"@serwist/sw": {
|
package/src/index.worker.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
+
import { PAGES_CACHE_NAME } from "./worker/constants.js";
|
|
1
2
|
import { defaultCache } from "./worker/defaultCache.js";
|
|
2
|
-
import { type DefinePageRuntimeCachingOptions, type PageRuntimeCaching, definePageRuntimeCaching } from "./worker/definePageRuntimeCaching.js";
|
|
3
3
|
|
|
4
|
-
export { defaultCache,
|
|
5
|
-
export type { DefinePageRuntimeCachingOptions, PageRuntimeCaching };
|
|
4
|
+
export { defaultCache, PAGES_CACHE_NAME };
|
|
@@ -1,141 +1,157 @@
|
|
|
1
|
+
import { ExpirationPlugin } from "@serwist/expiration";
|
|
2
|
+
import { RangeRequestsPlugin } from "@serwist/range-requests";
|
|
3
|
+
import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from "@serwist/strategies";
|
|
1
4
|
import type { RuntimeCaching } from "@serwist/sw";
|
|
2
|
-
import { definePageRuntimeCaching } from "./definePageRuntimeCaching.js";
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
import { PAGES_CACHE_NAME } from "./constants.js";
|
|
7
|
+
|
|
8
|
+
// Serwist RuntimeCaching config: https://serwist.pages.dev/docs/sw/register-runtime-caching
|
|
5
9
|
export const defaultCache = [
|
|
6
10
|
{
|
|
7
11
|
urlPattern: /^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,
|
|
8
|
-
handler:
|
|
9
|
-
options: {
|
|
12
|
+
handler: new CacheFirst({
|
|
10
13
|
cacheName: "google-fonts-webfonts",
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
plugins: [
|
|
15
|
+
new ExpirationPlugin({
|
|
16
|
+
maxEntries: 4,
|
|
17
|
+
maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days
|
|
18
|
+
}),
|
|
19
|
+
],
|
|
20
|
+
}),
|
|
16
21
|
},
|
|
17
22
|
{
|
|
18
23
|
urlPattern: /^https:\/\/fonts\.(?:googleapis)\.com\/.*/i,
|
|
19
|
-
handler:
|
|
20
|
-
options: {
|
|
24
|
+
handler: new StaleWhileRevalidate({
|
|
21
25
|
cacheName: "google-fonts-stylesheets",
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
plugins: [
|
|
27
|
+
new ExpirationPlugin({
|
|
28
|
+
maxEntries: 4,
|
|
29
|
+
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
|
|
30
|
+
}),
|
|
31
|
+
],
|
|
32
|
+
}),
|
|
27
33
|
},
|
|
28
34
|
{
|
|
29
35
|
urlPattern: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
|
|
30
|
-
handler:
|
|
31
|
-
options: {
|
|
36
|
+
handler: new StaleWhileRevalidate({
|
|
32
37
|
cacheName: "static-font-assets",
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
plugins: [
|
|
39
|
+
new ExpirationPlugin({
|
|
40
|
+
maxEntries: 4,
|
|
41
|
+
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
|
|
42
|
+
}),
|
|
43
|
+
],
|
|
44
|
+
}),
|
|
38
45
|
},
|
|
39
46
|
{
|
|
40
47
|
urlPattern: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
|
|
41
|
-
handler:
|
|
42
|
-
options: {
|
|
48
|
+
handler: new StaleWhileRevalidate({
|
|
43
49
|
cacheName: "static-image-assets",
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
plugins: [
|
|
51
|
+
new ExpirationPlugin({
|
|
52
|
+
maxEntries: 64,
|
|
53
|
+
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 days
|
|
54
|
+
}),
|
|
55
|
+
],
|
|
56
|
+
}),
|
|
49
57
|
},
|
|
50
58
|
{
|
|
51
59
|
urlPattern: /\/_next\/static.+\.js$/i,
|
|
52
|
-
handler:
|
|
53
|
-
options: {
|
|
60
|
+
handler: new CacheFirst({
|
|
54
61
|
cacheName: "next-static-js-assets",
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
plugins: [
|
|
63
|
+
new ExpirationPlugin({
|
|
64
|
+
maxEntries: 64,
|
|
65
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
66
|
+
}),
|
|
67
|
+
],
|
|
68
|
+
}),
|
|
60
69
|
},
|
|
61
70
|
{
|
|
62
71
|
urlPattern: /\/_next\/image\?url=.+$/i,
|
|
63
|
-
handler:
|
|
64
|
-
options: {
|
|
72
|
+
handler: new StaleWhileRevalidate({
|
|
65
73
|
cacheName: "next-image",
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
plugins: [
|
|
75
|
+
new ExpirationPlugin({
|
|
76
|
+
maxEntries: 64,
|
|
77
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
78
|
+
}),
|
|
79
|
+
],
|
|
80
|
+
}),
|
|
71
81
|
},
|
|
72
82
|
{
|
|
73
83
|
urlPattern: /\.(?:mp3|wav|ogg)$/i,
|
|
74
|
-
handler:
|
|
75
|
-
options: {
|
|
76
|
-
rangeRequests: true,
|
|
84
|
+
handler: new CacheFirst({
|
|
77
85
|
cacheName: "static-audio-assets",
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
plugins: [
|
|
87
|
+
new ExpirationPlugin({
|
|
88
|
+
maxEntries: 32,
|
|
89
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
90
|
+
}),
|
|
91
|
+
new RangeRequestsPlugin(),
|
|
92
|
+
],
|
|
93
|
+
}),
|
|
83
94
|
},
|
|
84
95
|
{
|
|
85
96
|
urlPattern: /\.(?:mp4|webm)$/i,
|
|
86
|
-
handler:
|
|
87
|
-
options: {
|
|
88
|
-
rangeRequests: true,
|
|
97
|
+
handler: new CacheFirst({
|
|
89
98
|
cacheName: "static-video-assets",
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
plugins: [
|
|
100
|
+
new ExpirationPlugin({
|
|
101
|
+
maxEntries: 32,
|
|
102
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
103
|
+
}),
|
|
104
|
+
new RangeRequestsPlugin(),
|
|
105
|
+
],
|
|
106
|
+
}),
|
|
95
107
|
},
|
|
96
108
|
{
|
|
97
109
|
urlPattern: /\.(?:js)$/i,
|
|
98
|
-
handler:
|
|
99
|
-
options: {
|
|
110
|
+
handler: new StaleWhileRevalidate({
|
|
100
111
|
cacheName: "static-js-assets",
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
112
|
+
plugins: [
|
|
113
|
+
new ExpirationPlugin({
|
|
114
|
+
maxEntries: 48,
|
|
115
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
116
|
+
}),
|
|
117
|
+
],
|
|
118
|
+
}),
|
|
106
119
|
},
|
|
107
120
|
{
|
|
108
121
|
urlPattern: /\.(?:css|less)$/i,
|
|
109
|
-
handler:
|
|
110
|
-
options: {
|
|
122
|
+
handler: new StaleWhileRevalidate({
|
|
111
123
|
cacheName: "static-style-assets",
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
124
|
+
plugins: [
|
|
125
|
+
new ExpirationPlugin({
|
|
126
|
+
maxEntries: 32,
|
|
127
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
128
|
+
}),
|
|
129
|
+
],
|
|
130
|
+
}),
|
|
117
131
|
},
|
|
118
132
|
{
|
|
119
133
|
urlPattern: /\/_next\/data\/.+\/.+\.json$/i,
|
|
120
|
-
handler:
|
|
121
|
-
options: {
|
|
134
|
+
handler: new StaleWhileRevalidate({
|
|
122
135
|
cacheName: "next-data",
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
136
|
+
plugins: [
|
|
137
|
+
new ExpirationPlugin({
|
|
138
|
+
maxEntries: 32,
|
|
139
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
140
|
+
}),
|
|
141
|
+
],
|
|
142
|
+
}),
|
|
128
143
|
},
|
|
129
144
|
{
|
|
130
145
|
urlPattern: /\.(?:json|xml|csv)$/i,
|
|
131
|
-
handler:
|
|
132
|
-
options: {
|
|
146
|
+
handler: new NetworkFirst({
|
|
133
147
|
cacheName: "static-data-assets",
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
148
|
+
plugins: [
|
|
149
|
+
new ExpirationPlugin({
|
|
150
|
+
maxEntries: 32,
|
|
151
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
152
|
+
}),
|
|
153
|
+
],
|
|
154
|
+
}),
|
|
139
155
|
},
|
|
140
156
|
{
|
|
141
157
|
urlPattern: ({ sameOrigin, url: { pathname } }) => {
|
|
@@ -152,72 +168,79 @@ export const defaultCache = [
|
|
|
152
168
|
|
|
153
169
|
return false;
|
|
154
170
|
},
|
|
155
|
-
handler: "NetworkFirst",
|
|
156
171
|
method: "GET",
|
|
157
|
-
|
|
172
|
+
handler: new NetworkFirst({
|
|
158
173
|
cacheName: "apis",
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
174
|
+
plugins: [
|
|
175
|
+
new ExpirationPlugin({
|
|
176
|
+
maxEntries: 16,
|
|
177
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
178
|
+
}),
|
|
179
|
+
],
|
|
163
180
|
networkTimeoutSeconds: 10, // fallback to cache if API does not response within 10 seconds
|
|
164
|
-
},
|
|
181
|
+
}),
|
|
165
182
|
},
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
183
|
+
{
|
|
184
|
+
urlPattern: ({ request, url: { pathname }, sameOrigin }) =>
|
|
185
|
+
request.headers.get("RSC") === "1" && request.headers.get("Next-Router-Prefetch") === "1" && sameOrigin && !pathname.startsWith("/api/"),
|
|
186
|
+
handler: new NetworkFirst({
|
|
187
|
+
cacheName: PAGES_CACHE_NAME.rscPrefetch,
|
|
188
|
+
plugins: [
|
|
189
|
+
new ExpirationPlugin({
|
|
173
190
|
maxEntries: 32,
|
|
174
191
|
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
175
|
-
},
|
|
176
|
-
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
192
|
+
}),
|
|
193
|
+
],
|
|
194
|
+
}),
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
urlPattern: ({ request, url: { pathname }, sameOrigin }) => request.headers.get("RSC") === "1" && sameOrigin && !pathname.startsWith("/api/"),
|
|
198
|
+
handler: new NetworkFirst({
|
|
199
|
+
cacheName: PAGES_CACHE_NAME.rsc,
|
|
200
|
+
plugins: [
|
|
201
|
+
new ExpirationPlugin({
|
|
183
202
|
maxEntries: 32,
|
|
184
203
|
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
185
|
-
},
|
|
186
|
-
|
|
187
|
-
},
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
204
|
+
}),
|
|
205
|
+
],
|
|
206
|
+
}),
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
urlPattern: ({ request, url: { pathname }, sameOrigin }) =>
|
|
210
|
+
request.headers.get("Content-Type")?.includes("text/html") && sameOrigin && !pathname.startsWith("/api/"),
|
|
211
|
+
handler: new NetworkFirst({
|
|
212
|
+
cacheName: PAGES_CACHE_NAME.html,
|
|
213
|
+
plugins: [
|
|
214
|
+
new ExpirationPlugin({
|
|
194
215
|
maxEntries: 32,
|
|
195
216
|
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
196
|
-
},
|
|
197
|
-
|
|
198
|
-
},
|
|
199
|
-
}
|
|
217
|
+
}),
|
|
218
|
+
],
|
|
219
|
+
}),
|
|
220
|
+
},
|
|
200
221
|
{
|
|
201
222
|
urlPattern: ({ url: { pathname }, sameOrigin }) => sameOrigin && !pathname.startsWith("/api/"),
|
|
202
|
-
handler:
|
|
203
|
-
options: {
|
|
223
|
+
handler: new NetworkFirst({
|
|
204
224
|
cacheName: "others",
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
225
|
+
plugins: [
|
|
226
|
+
new ExpirationPlugin({
|
|
227
|
+
maxEntries: 32,
|
|
228
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
229
|
+
}),
|
|
230
|
+
],
|
|
231
|
+
}),
|
|
210
232
|
},
|
|
211
233
|
{
|
|
212
234
|
urlPattern: ({ sameOrigin }) => !sameOrigin,
|
|
213
|
-
handler:
|
|
214
|
-
options: {
|
|
235
|
+
handler: new NetworkFirst({
|
|
215
236
|
cacheName: "cross-origin",
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
237
|
+
plugins: [
|
|
238
|
+
new ExpirationPlugin({
|
|
239
|
+
maxEntries: 32,
|
|
240
|
+
maxAgeSeconds: 60 * 60, // 1 hour
|
|
241
|
+
}),
|
|
242
|
+
],
|
|
220
243
|
networkTimeoutSeconds: 10,
|
|
221
|
-
},
|
|
244
|
+
}),
|
|
222
245
|
},
|
|
223
246
|
] satisfies RuntimeCaching[];
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { RuntimeCaching } from "@serwist/sw";
|
|
2
|
-
export interface PageRuntimeCaching extends Omit<RuntimeCaching, "options"> {
|
|
3
|
-
options?: Omit<NonNullable<RuntimeCaching["options"]>, "cacheName">;
|
|
4
|
-
}
|
|
5
|
-
export interface DefinePageRuntimeCachingOptions {
|
|
6
|
-
rscPrefetch?: PageRuntimeCaching;
|
|
7
|
-
rsc?: PageRuntimeCaching;
|
|
8
|
-
html?: PageRuntimeCaching;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Conveniently define three `runtimeCaching` entries for Next.js pages.
|
|
12
|
-
* @param options
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
export declare const definePageRuntimeCaching: ({ rscPrefetch, rsc, html }: DefinePageRuntimeCachingOptions) => RuntimeCaching[];
|
|
16
|
-
//# sourceMappingURL=definePageRuntimeCaching.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"definePageRuntimeCaching.d.ts","sourceRoot":"","sources":["../../src/worker/definePageRuntimeCaching.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC;IACzE,OAAO,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;CACrE;AAED,MAAM,WAAW,+BAA+B;IAC9C,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,GAAG,CAAC,EAAE,kBAAkB,CAAC;IACzB,IAAI,CAAC,EAAE,kBAAkB,CAAC;CAC3B;AAED;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,+BAAgC,+BAA+B,KAAG,cAAc,EAiBpH,CAAC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { RuntimeCaching } from "@serwist/sw";
|
|
2
|
-
import { nonNullable } from "@serwist/utils";
|
|
3
|
-
|
|
4
|
-
export interface PageRuntimeCaching extends Omit<RuntimeCaching, "options"> {
|
|
5
|
-
options?: Omit<NonNullable<RuntimeCaching["options"]>, "cacheName">;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface DefinePageRuntimeCachingOptions {
|
|
9
|
-
rscPrefetch?: PageRuntimeCaching;
|
|
10
|
-
rsc?: PageRuntimeCaching;
|
|
11
|
-
html?: PageRuntimeCaching;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Conveniently define three `runtimeCaching` entries for Next.js pages.
|
|
16
|
-
* @param options
|
|
17
|
-
* @returns
|
|
18
|
-
*/
|
|
19
|
-
export const definePageRuntimeCaching = ({ rscPrefetch, rsc, html }: DefinePageRuntimeCachingOptions): RuntimeCaching[] => {
|
|
20
|
-
const pageRcs = [rscPrefetch, rsc, html] as RuntimeCaching[];
|
|
21
|
-
|
|
22
|
-
if (pageRcs[0]) {
|
|
23
|
-
if (!pageRcs[0].options) pageRcs[0].options = {};
|
|
24
|
-
pageRcs[0].options.cacheName = "pages-rsc-prefetch";
|
|
25
|
-
}
|
|
26
|
-
if (pageRcs[1]) {
|
|
27
|
-
if (!pageRcs[1].options) pageRcs[1].options = {};
|
|
28
|
-
pageRcs[1].options.cacheName = "pages-rsc";
|
|
29
|
-
}
|
|
30
|
-
if (pageRcs[2]) {
|
|
31
|
-
if (!pageRcs[2].options) pageRcs[2].options = {};
|
|
32
|
-
pageRcs[2].options.cacheName = "pages";
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return pageRcs.filter(nonNullable);
|
|
36
|
-
};
|