@serwist/next 9.0.0-preview.14 → 9.0.0-preview.16

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.
@@ -8,7 +8,7 @@ const PAGES_CACHE_NAME = {
8
8
  html: "pages"
9
9
  };
10
10
 
11
- const defaultCache = [
11
+ const defaultCache = process.env.NODE_ENV !== "production" ? [] : [
12
12
  {
13
13
  matcher: /^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,
14
14
  handler: new CacheFirst({
@@ -16,7 +16,8 @@ const defaultCache = [
16
16
  plugins: [
17
17
  new ExpirationPlugin({
18
18
  maxEntries: 4,
19
- maxAgeSeconds: 365 * 24 * 60 * 60
19
+ maxAgeSeconds: 365 * 24 * 60 * 60,
20
+ maxAgeFrom: "last-used"
20
21
  })
21
22
  ]
22
23
  })
@@ -28,7 +29,8 @@ const defaultCache = [
28
29
  plugins: [
29
30
  new ExpirationPlugin({
30
31
  maxEntries: 4,
31
- maxAgeSeconds: 7 * 24 * 60 * 60
32
+ maxAgeSeconds: 7 * 24 * 60 * 60,
33
+ maxAgeFrom: "last-used"
32
34
  })
33
35
  ]
34
36
  })
@@ -40,7 +42,8 @@ const defaultCache = [
40
42
  plugins: [
41
43
  new ExpirationPlugin({
42
44
  maxEntries: 4,
43
- maxAgeSeconds: 7 * 24 * 60 * 60
45
+ maxAgeSeconds: 7 * 24 * 60 * 60,
46
+ maxAgeFrom: "last-used"
44
47
  })
45
48
  ]
46
49
  })
@@ -52,7 +55,8 @@ const defaultCache = [
52
55
  plugins: [
53
56
  new ExpirationPlugin({
54
57
  maxEntries: 64,
55
- maxAgeSeconds: 30 * 24 * 60 * 60
58
+ maxAgeSeconds: 30 * 24 * 60 * 60,
59
+ maxAgeFrom: "last-used"
56
60
  })
57
61
  ]
58
62
  })
@@ -64,7 +68,8 @@ const defaultCache = [
64
68
  plugins: [
65
69
  new ExpirationPlugin({
66
70
  maxEntries: 64,
67
- maxAgeSeconds: 24 * 60 * 60
71
+ maxAgeSeconds: 24 * 60 * 60,
72
+ maxAgeFrom: "last-used"
68
73
  })
69
74
  ]
70
75
  })
@@ -76,7 +81,8 @@ const defaultCache = [
76
81
  plugins: [
77
82
  new ExpirationPlugin({
78
83
  maxEntries: 64,
79
- maxAgeSeconds: 24 * 60 * 60
84
+ maxAgeSeconds: 24 * 60 * 60,
85
+ maxAgeFrom: "last-used"
80
86
  })
81
87
  ]
82
88
  })
@@ -88,7 +94,8 @@ const defaultCache = [
88
94
  plugins: [
89
95
  new ExpirationPlugin({
90
96
  maxEntries: 32,
91
- maxAgeSeconds: 24 * 60 * 60
97
+ maxAgeSeconds: 24 * 60 * 60,
98
+ maxAgeFrom: "last-used"
92
99
  }),
93
100
  new RangeRequestsPlugin()
94
101
  ]
@@ -101,7 +108,8 @@ const defaultCache = [
101
108
  plugins: [
102
109
  new ExpirationPlugin({
103
110
  maxEntries: 32,
104
- maxAgeSeconds: 24 * 60 * 60
111
+ maxAgeSeconds: 24 * 60 * 60,
112
+ maxAgeFrom: "last-used"
105
113
  }),
106
114
  new RangeRequestsPlugin()
107
115
  ]
@@ -114,7 +122,8 @@ const defaultCache = [
114
122
  plugins: [
115
123
  new ExpirationPlugin({
116
124
  maxEntries: 48,
117
- maxAgeSeconds: 24 * 60 * 60
125
+ maxAgeSeconds: 24 * 60 * 60,
126
+ maxAgeFrom: "last-used"
118
127
  })
119
128
  ]
120
129
  })
@@ -126,7 +135,8 @@ const defaultCache = [
126
135
  plugins: [
127
136
  new ExpirationPlugin({
128
137
  maxEntries: 32,
129
- maxAgeSeconds: 24 * 60 * 60
138
+ maxAgeSeconds: 24 * 60 * 60,
139
+ maxAgeFrom: "last-used"
130
140
  })
131
141
  ]
132
142
  })
@@ -138,7 +148,8 @@ const defaultCache = [
138
148
  plugins: [
139
149
  new ExpirationPlugin({
140
150
  maxEntries: 32,
141
- maxAgeSeconds: 24 * 60 * 60
151
+ maxAgeSeconds: 24 * 60 * 60,
152
+ maxAgeFrom: "last-used"
142
153
  })
143
154
  ]
144
155
  })
@@ -150,7 +161,8 @@ const defaultCache = [
150
161
  plugins: [
151
162
  new ExpirationPlugin({
152
163
  maxEntries: 32,
153
- maxAgeSeconds: 24 * 60 * 60
164
+ maxAgeSeconds: 24 * 60 * 60,
165
+ maxAgeFrom: "last-used"
154
166
  })
155
167
  ]
156
168
  })
@@ -171,7 +183,8 @@ const defaultCache = [
171
183
  plugins: [
172
184
  new ExpirationPlugin({
173
185
  maxEntries: 16,
174
- maxAgeSeconds: 24 * 60 * 60
186
+ maxAgeSeconds: 24 * 60 * 60,
187
+ maxAgeFrom: "last-used"
175
188
  })
176
189
  ],
177
190
  networkTimeoutSeconds: 10
@@ -1,3 +1,9 @@
1
1
  import type { RuntimeCaching } from "@serwist/sw";
2
+ /**
3
+ * The default, recommended list of caching strategies for applications
4
+ * built with Next.js.
5
+ *
6
+ * @see https://serwist.pages.dev/docs/next/worker-exports#default-cache
7
+ */
2
8
  export declare const defaultCache: RuntimeCaching[];
3
9
  //# sourceMappingURL=defaultCache.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"defaultCache.d.ts","sourceRoot":"","sources":["../../src/worker/defaultCache.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAKlD,eAAO,MAAM,YAAY,EAAE,cAAc,EA6OxC,CAAC"}
1
+ {"version":3,"file":"defaultCache.d.ts","sourceRoot":"","sources":["../../src/worker/defaultCache.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAIlD;;;;;GAKG;AACH,eAAO,MAAM,YAAY,EAAE,cAAc,EAiQlC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/next",
3
- "version": "9.0.0-preview.14",
3
+ "version": "9.0.0-preview.16",
4
4
  "type": "module",
5
5
  "description": "A module that integrates Serwist into your Next.js application.",
6
6
  "files": [
@@ -65,31 +65,31 @@
65
65
  "chalk": "5.3.0",
66
66
  "glob": "10.3.10",
67
67
  "zod": "3.22.4",
68
- "@serwist/build": "9.0.0-preview.14",
69
- "@serwist/core": "9.0.0-preview.14",
70
- "@serwist/expiration": "9.0.0-preview.14",
71
- "@serwist/range-requests": "9.0.0-preview.14",
72
- "@serwist/strategies": "9.0.0-preview.14",
73
- "@serwist/webpack-plugin": "9.0.0-preview.14",
74
- "@serwist/window": "9.0.0-preview.14"
68
+ "@serwist/build": "9.0.0-preview.16",
69
+ "@serwist/core": "9.0.0-preview.16",
70
+ "@serwist/expiration": "9.0.0-preview.16",
71
+ "@serwist/range-requests": "9.0.0-preview.16",
72
+ "@serwist/strategies": "9.0.0-preview.16",
73
+ "@serwist/webpack-plugin": "9.0.0-preview.16",
74
+ "@serwist/window": "9.0.0-preview.16"
75
75
  },
76
76
  "devDependencies": {
77
- "@types/node": "20.11.26",
78
- "next": "14.1.3",
77
+ "@types/node": "20.11.30",
78
+ "next": "14.1.4",
79
79
  "react": "18.2.0",
80
80
  "react-dom": "18.2.0",
81
81
  "rollup": "4.13.0",
82
- "type-fest": "4.12.0",
83
- "typescript": "5.5.0-dev.20240312",
84
- "webpack": "5.90.3",
85
- "@serwist/constants": "9.0.0-preview.14",
86
- "@serwist/sw": "9.0.0-preview.14",
87
- "@serwist/utils": "9.0.0-preview.14"
82
+ "type-fest": "4.13.1",
83
+ "typescript": "5.5.0-dev.20240323",
84
+ "webpack": "5.91.0",
85
+ "@serwist/constants": "9.0.0-preview.16",
86
+ "@serwist/sw": "9.0.0-preview.16",
87
+ "@serwist/utils": "9.0.0-preview.16"
88
88
  },
89
89
  "peerDependencies": {
90
90
  "next": ">=14.0.0",
91
91
  "typescript": ">=5.0.0",
92
- "@serwist/sw": "9.0.0-preview.14"
92
+ "@serwist/sw": "9.0.0-preview.16"
93
93
  },
94
94
  "peerDependenciesMeta": {
95
95
  "@serwist/sw": {
@@ -5,242 +5,267 @@ import type { RuntimeCaching } from "@serwist/sw";
5
5
 
6
6
  import { PAGES_CACHE_NAME } from "./constants.js";
7
7
 
8
- // Serwist RuntimeCaching config: https://serwist.pages.dev/docs/sw/register-runtime-caching
9
- export const defaultCache: RuntimeCaching[] = [
10
- {
11
- matcher: /^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,
12
- handler: new CacheFirst({
13
- cacheName: "google-fonts-webfonts",
14
- plugins: [
15
- new ExpirationPlugin({
16
- maxEntries: 4,
17
- maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days
18
- }),
19
- ],
20
- }),
21
- },
22
- {
23
- matcher: /^https:\/\/fonts\.(?:googleapis)\.com\/.*/i,
24
- handler: new StaleWhileRevalidate({
25
- cacheName: "google-fonts-stylesheets",
26
- plugins: [
27
- new ExpirationPlugin({
28
- maxEntries: 4,
29
- maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
30
- }),
31
- ],
32
- }),
33
- },
34
- {
35
- matcher: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
36
- handler: new StaleWhileRevalidate({
37
- cacheName: "static-font-assets",
38
- plugins: [
39
- new ExpirationPlugin({
40
- maxEntries: 4,
41
- maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
42
- }),
43
- ],
44
- }),
45
- },
46
- {
47
- matcher: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
48
- handler: new StaleWhileRevalidate({
49
- cacheName: "static-image-assets",
50
- plugins: [
51
- new ExpirationPlugin({
52
- maxEntries: 64,
53
- maxAgeSeconds: 30 * 24 * 60 * 60, // 30 days
54
- }),
55
- ],
56
- }),
57
- },
58
- {
59
- matcher: /\/_next\/static.+\.js$/i,
60
- handler: new CacheFirst({
61
- cacheName: "next-static-js-assets",
62
- plugins: [
63
- new ExpirationPlugin({
64
- maxEntries: 64,
65
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
66
- }),
67
- ],
68
- }),
69
- },
70
- {
71
- matcher: /\/_next\/image\?url=.+$/i,
72
- handler: new StaleWhileRevalidate({
73
- cacheName: "next-image",
74
- plugins: [
75
- new ExpirationPlugin({
76
- maxEntries: 64,
77
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
78
- }),
79
- ],
80
- }),
81
- },
82
- {
83
- matcher: /\.(?:mp3|wav|ogg)$/i,
84
- handler: new CacheFirst({
85
- cacheName: "static-audio-assets",
86
- plugins: [
87
- new ExpirationPlugin({
88
- maxEntries: 32,
89
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
90
- }),
91
- new RangeRequestsPlugin(),
92
- ],
93
- }),
94
- },
95
- {
96
- matcher: /\.(?:mp4|webm)$/i,
97
- handler: new CacheFirst({
98
- cacheName: "static-video-assets",
99
- plugins: [
100
- new ExpirationPlugin({
101
- maxEntries: 32,
102
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
103
- }),
104
- new RangeRequestsPlugin(),
105
- ],
106
- }),
107
- },
108
- {
109
- matcher: /\.(?:js)$/i,
110
- handler: new StaleWhileRevalidate({
111
- cacheName: "static-js-assets",
112
- plugins: [
113
- new ExpirationPlugin({
114
- maxEntries: 48,
115
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
116
- }),
117
- ],
118
- }),
119
- },
120
- {
121
- matcher: /\.(?:css|less)$/i,
122
- handler: new StaleWhileRevalidate({
123
- cacheName: "static-style-assets",
124
- plugins: [
125
- new ExpirationPlugin({
126
- maxEntries: 32,
127
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
128
- }),
129
- ],
130
- }),
131
- },
132
- {
133
- matcher: /\/_next\/data\/.+\/.+\.json$/i,
134
- handler: new NetworkFirst({
135
- cacheName: "next-data",
136
- plugins: [
137
- new ExpirationPlugin({
138
- maxEntries: 32,
139
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
140
- }),
141
- ],
142
- }),
143
- },
144
- {
145
- matcher: /\.(?:json|xml|csv)$/i,
146
- handler: new NetworkFirst({
147
- cacheName: "static-data-assets",
148
- plugins: [
149
- new ExpirationPlugin({
150
- maxEntries: 32,
151
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
152
- }),
153
- ],
154
- }),
155
- },
156
- {
157
- matcher: ({ sameOrigin, url: { pathname } }) => {
158
- // Exclude /api/auth/callback/* to fix OAuth workflow in Safari without having an impact on other environments
159
- // The above route is the default for next-auth, you may need to change it if your OAuth workflow has a different callback route
160
- // Issue: https://github.com/shadowwalker/next-pwa/issues/131#issuecomment-821894809
161
- if (!sameOrigin || pathname.startsWith("/api/auth/callback")) {
162
- return false;
163
- }
8
+ /**
9
+ * The default, recommended list of caching strategies for applications
10
+ * built with Next.js.
11
+ *
12
+ * @see https://serwist.pages.dev/docs/next/worker-exports#default-cache
13
+ */
14
+ export const defaultCache: RuntimeCaching[] =
15
+ process.env.NODE_ENV !== "production"
16
+ ? []
17
+ : [
18
+ {
19
+ matcher: /^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,
20
+ handler: new CacheFirst({
21
+ cacheName: "google-fonts-webfonts",
22
+ plugins: [
23
+ new ExpirationPlugin({
24
+ maxEntries: 4,
25
+ maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days
26
+ maxAgeFrom: "last-used",
27
+ }),
28
+ ],
29
+ }),
30
+ },
31
+ {
32
+ matcher: /^https:\/\/fonts\.(?:googleapis)\.com\/.*/i,
33
+ handler: new StaleWhileRevalidate({
34
+ cacheName: "google-fonts-stylesheets",
35
+ plugins: [
36
+ new ExpirationPlugin({
37
+ maxEntries: 4,
38
+ maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
39
+ maxAgeFrom: "last-used",
40
+ }),
41
+ ],
42
+ }),
43
+ },
44
+ {
45
+ matcher: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
46
+ handler: new StaleWhileRevalidate({
47
+ cacheName: "static-font-assets",
48
+ plugins: [
49
+ new ExpirationPlugin({
50
+ maxEntries: 4,
51
+ maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
52
+ maxAgeFrom: "last-used",
53
+ }),
54
+ ],
55
+ }),
56
+ },
57
+ {
58
+ matcher: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
59
+ handler: new StaleWhileRevalidate({
60
+ cacheName: "static-image-assets",
61
+ plugins: [
62
+ new ExpirationPlugin({
63
+ maxEntries: 64,
64
+ maxAgeSeconds: 30 * 24 * 60 * 60, // 30 days
65
+ maxAgeFrom: "last-used",
66
+ }),
67
+ ],
68
+ }),
69
+ },
70
+ {
71
+ matcher: /\/_next\/static.+\.js$/i,
72
+ handler: new CacheFirst({
73
+ cacheName: "next-static-js-assets",
74
+ plugins: [
75
+ new ExpirationPlugin({
76
+ maxEntries: 64,
77
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
78
+ maxAgeFrom: "last-used",
79
+ }),
80
+ ],
81
+ }),
82
+ },
83
+ {
84
+ matcher: /\/_next\/image\?url=.+$/i,
85
+ handler: new StaleWhileRevalidate({
86
+ cacheName: "next-image",
87
+ plugins: [
88
+ new ExpirationPlugin({
89
+ maxEntries: 64,
90
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
91
+ maxAgeFrom: "last-used",
92
+ }),
93
+ ],
94
+ }),
95
+ },
96
+ {
97
+ matcher: /\.(?:mp3|wav|ogg)$/i,
98
+ handler: new CacheFirst({
99
+ cacheName: "static-audio-assets",
100
+ plugins: [
101
+ new ExpirationPlugin({
102
+ maxEntries: 32,
103
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
104
+ maxAgeFrom: "last-used",
105
+ }),
106
+ new RangeRequestsPlugin(),
107
+ ],
108
+ }),
109
+ },
110
+ {
111
+ matcher: /\.(?:mp4|webm)$/i,
112
+ handler: new CacheFirst({
113
+ cacheName: "static-video-assets",
114
+ plugins: [
115
+ new ExpirationPlugin({
116
+ maxEntries: 32,
117
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
118
+ maxAgeFrom: "last-used",
119
+ }),
120
+ new RangeRequestsPlugin(),
121
+ ],
122
+ }),
123
+ },
124
+ {
125
+ matcher: /\.(?:js)$/i,
126
+ handler: new StaleWhileRevalidate({
127
+ cacheName: "static-js-assets",
128
+ plugins: [
129
+ new ExpirationPlugin({
130
+ maxEntries: 48,
131
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
132
+ maxAgeFrom: "last-used",
133
+ }),
134
+ ],
135
+ }),
136
+ },
137
+ {
138
+ matcher: /\.(?:css|less)$/i,
139
+ handler: new StaleWhileRevalidate({
140
+ cacheName: "static-style-assets",
141
+ plugins: [
142
+ new ExpirationPlugin({
143
+ maxEntries: 32,
144
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
145
+ maxAgeFrom: "last-used",
146
+ }),
147
+ ],
148
+ }),
149
+ },
150
+ {
151
+ matcher: /\/_next\/data\/.+\/.+\.json$/i,
152
+ handler: new NetworkFirst({
153
+ cacheName: "next-data",
154
+ plugins: [
155
+ new ExpirationPlugin({
156
+ maxEntries: 32,
157
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
158
+ maxAgeFrom: "last-used",
159
+ }),
160
+ ],
161
+ }),
162
+ },
163
+ {
164
+ matcher: /\.(?:json|xml|csv)$/i,
165
+ handler: new NetworkFirst({
166
+ cacheName: "static-data-assets",
167
+ plugins: [
168
+ new ExpirationPlugin({
169
+ maxEntries: 32,
170
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
171
+ maxAgeFrom: "last-used",
172
+ }),
173
+ ],
174
+ }),
175
+ },
176
+ {
177
+ matcher: ({ sameOrigin, url: { pathname } }) => {
178
+ // Exclude /api/auth/callback/* to fix OAuth workflow in Safari without having
179
+ // an impact on other environments
180
+ // The above route is the default for next-auth, you may need to change it if
181
+ // your OAuth workflow has a different callback route.
182
+ // Issue: https://github.com/shadowwalker/next-pwa/issues/131#issuecomment-821894809
183
+ // TODO(ducanhgh): Investigate Auth.js's "/api/auth/*" failing when we allow them
184
+ // to be cached (the current behaviour).
185
+ if (!sameOrigin || pathname.startsWith("/api/auth/callback")) {
186
+ return false;
187
+ }
164
188
 
165
- if (pathname.startsWith("/api/")) {
166
- return true;
167
- }
189
+ if (pathname.startsWith("/api/")) {
190
+ return true;
191
+ }
168
192
 
169
- return false;
170
- },
171
- method: "GET",
172
- handler: new NetworkFirst({
173
- cacheName: "apis",
174
- plugins: [
175
- new ExpirationPlugin({
176
- maxEntries: 16,
177
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
178
- }),
179
- ],
180
- networkTimeoutSeconds: 10, // fallback to cache if API does not response within 10 seconds
181
- }),
182
- },
183
- {
184
- matcher: ({ 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({
190
- maxEntries: 32,
191
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
192
- }),
193
- ],
194
- }),
195
- },
196
- {
197
- matcher: ({ 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({
202
- maxEntries: 32,
203
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
204
- }),
205
- ],
206
- }),
207
- },
208
- {
209
- matcher: ({ 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({
215
- maxEntries: 32,
216
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
217
- }),
218
- ],
219
- }),
220
- },
221
- {
222
- matcher: ({ url: { pathname }, sameOrigin }) => sameOrigin && !pathname.startsWith("/api/"),
223
- handler: new NetworkFirst({
224
- cacheName: "others",
225
- plugins: [
226
- new ExpirationPlugin({
227
- maxEntries: 32,
228
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
229
- }),
230
- ],
231
- }),
232
- },
233
- {
234
- matcher: ({ sameOrigin }) => !sameOrigin,
235
- handler: new NetworkFirst({
236
- cacheName: "cross-origin",
237
- plugins: [
238
- new ExpirationPlugin({
239
- maxEntries: 32,
240
- maxAgeSeconds: 60 * 60, // 1 hour
241
- }),
242
- ],
243
- networkTimeoutSeconds: 10,
244
- }),
245
- },
246
- ];
193
+ return false;
194
+ },
195
+ method: "GET",
196
+ handler: new NetworkFirst({
197
+ cacheName: "apis",
198
+ plugins: [
199
+ new ExpirationPlugin({
200
+ maxEntries: 16,
201
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
202
+ maxAgeFrom: "last-used",
203
+ }),
204
+ ],
205
+ networkTimeoutSeconds: 10, // fallback to cache if API does not response within 10 seconds
206
+ }),
207
+ },
208
+ {
209
+ matcher: ({ request, url: { pathname }, sameOrigin }) =>
210
+ request.headers.get("RSC") === "1" && request.headers.get("Next-Router-Prefetch") === "1" && sameOrigin && !pathname.startsWith("/api/"),
211
+ handler: new NetworkFirst({
212
+ cacheName: PAGES_CACHE_NAME.rscPrefetch,
213
+ plugins: [
214
+ new ExpirationPlugin({
215
+ maxEntries: 32,
216
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
217
+ }),
218
+ ],
219
+ }),
220
+ },
221
+ {
222
+ matcher: ({ request, url: { pathname }, sameOrigin }) => request.headers.get("RSC") === "1" && sameOrigin && !pathname.startsWith("/api/"),
223
+ handler: new NetworkFirst({
224
+ cacheName: PAGES_CACHE_NAME.rsc,
225
+ plugins: [
226
+ new ExpirationPlugin({
227
+ maxEntries: 32,
228
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
229
+ }),
230
+ ],
231
+ }),
232
+ },
233
+ {
234
+ matcher: ({ request, url: { pathname }, sameOrigin }) =>
235
+ request.headers.get("Content-Type")?.includes("text/html") && sameOrigin && !pathname.startsWith("/api/"),
236
+ handler: new NetworkFirst({
237
+ cacheName: PAGES_CACHE_NAME.html,
238
+ plugins: [
239
+ new ExpirationPlugin({
240
+ maxEntries: 32,
241
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
242
+ }),
243
+ ],
244
+ }),
245
+ },
246
+ {
247
+ matcher: ({ url: { pathname }, sameOrigin }) => sameOrigin && !pathname.startsWith("/api/"),
248
+ handler: new NetworkFirst({
249
+ cacheName: "others",
250
+ plugins: [
251
+ new ExpirationPlugin({
252
+ maxEntries: 32,
253
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
254
+ }),
255
+ ],
256
+ }),
257
+ },
258
+ {
259
+ matcher: ({ sameOrigin }) => !sameOrigin,
260
+ handler: new NetworkFirst({
261
+ cacheName: "cross-origin",
262
+ plugins: [
263
+ new ExpirationPlugin({
264
+ maxEntries: 32,
265
+ maxAgeSeconds: 60 * 60, // 1 hour
266
+ }),
267
+ ],
268
+ networkTimeoutSeconds: 10,
269
+ }),
270
+ },
271
+ ];