@serwist/svelte 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.
- package/dist/index.worker.d.ts +6 -0
- package/dist/index.worker.d.ts.map +1 -1
- package/dist/index.worker.js +18 -9
- package/package.json +9 -9
- package/src/index.worker.ts +110 -93
package/dist/index.worker.d.ts
CHANGED
@@ -59,5 +59,11 @@ export interface GetPrecacheManifestOptions {
|
|
59
59
|
*/
|
60
60
|
export declare const getPrecacheManifest: ({ precacheImmutable, precacheStatic, precachePrerendered, staticRevisions, manifestTransforms, }?: GetPrecacheManifestOptions) => PrecacheEntry[] | undefined;
|
61
61
|
export declare const defaultIgnoreUrlParameters: RegExp[];
|
62
|
+
/**
|
63
|
+
* The default, recommended list of caching strategies for applications
|
64
|
+
* built with SvelteKit.
|
65
|
+
*
|
66
|
+
* @see https://serwist.pages.dev/docs/svelte/worker-exports#default-cache
|
67
|
+
*/
|
62
68
|
export declare const defaultCache: RuntimeCaching[];
|
63
69
|
//# sourceMappingURL=index.worker.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.worker.d.ts","sourceRoot":"","sources":["../src/index.worker.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
1
|
+
{"version":3,"file":"index.worker.d.ts","sourceRoot":"","sources":["../src/index.worker.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,OAAO,EACL,IAAI,IAAI,QAAQ,EAChB,KAAK,IAAI,eAAe,EACxB,KAAK,IAAI,YAAY,EACrB,WAAW,IAAI,iBAAiB,EAChC,OAAO,IAAI,oBAAoB,EAChC,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,YAAY,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,CAAC;AAE5F,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAExE,MAAM,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK;IAC7D,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CACjC,CAAC;AAEF,MAAM,WAAW,0BAA0B;IACzC;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;;;;;;;OAUG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAC1C;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,sGAM7B,0BAA0B,KAAQ,aAAa,EAAE,GAAG,SA2CtD,CAAC;AAEF,eAAO,MAAM,0BAA0B,UAAgC,CAAC;AAExE;;;;;GAKG;AACH,eAAO,MAAM,YAAY,EAAE,cAAc,EA8GpC,CAAC"}
|
package/dist/index.worker.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import { logger } from '@serwist/core/internal';
|
2
2
|
import { ExpirationPlugin } from '@serwist/expiration';
|
3
3
|
import { CacheFirst, StaleWhileRevalidate, NetworkFirst } from '@serwist/strategies';
|
4
|
+
import { dev } from '$app/environment';
|
4
5
|
import { build, files, prerendered, version } from '$service-worker';
|
5
6
|
export { base as basePath, build as immutableAssets, prerendered as prerenderedRoutes, version as serviceWorkerVersion, files as staticAssets } from '$service-worker';
|
6
7
|
|
@@ -47,7 +48,7 @@ const getPrecacheManifest = ({ precacheImmutable = true, precacheStatic = true,
|
|
47
48
|
const defaultIgnoreUrlParameters = [
|
48
49
|
/^x-sveltekit-invalidated$/
|
49
50
|
];
|
50
|
-
const defaultCache = [
|
51
|
+
const defaultCache = dev ? [] : [
|
51
52
|
{
|
52
53
|
matcher: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,
|
53
54
|
handler: new CacheFirst({
|
@@ -55,7 +56,8 @@ const defaultCache = [
|
|
55
56
|
plugins: [
|
56
57
|
new ExpirationPlugin({
|
57
58
|
maxEntries: 4,
|
58
|
-
maxAgeSeconds: 365 * 24 * 60 * 60
|
59
|
+
maxAgeSeconds: 365 * 24 * 60 * 60,
|
60
|
+
maxAgeFrom: "last-used"
|
59
61
|
})
|
60
62
|
]
|
61
63
|
})
|
@@ -67,7 +69,8 @@ const defaultCache = [
|
|
67
69
|
plugins: [
|
68
70
|
new ExpirationPlugin({
|
69
71
|
maxEntries: 4,
|
70
|
-
maxAgeSeconds: 7 * 24 * 60 * 60
|
72
|
+
maxAgeSeconds: 7 * 24 * 60 * 60,
|
73
|
+
maxAgeFrom: "last-used"
|
71
74
|
})
|
72
75
|
]
|
73
76
|
})
|
@@ -79,7 +82,8 @@ const defaultCache = [
|
|
79
82
|
plugins: [
|
80
83
|
new ExpirationPlugin({
|
81
84
|
maxEntries: 64,
|
82
|
-
maxAgeSeconds: 24 * 60 * 60
|
85
|
+
maxAgeSeconds: 24 * 60 * 60,
|
86
|
+
maxAgeFrom: "last-used"
|
83
87
|
})
|
84
88
|
]
|
85
89
|
})
|
@@ -91,7 +95,8 @@ const defaultCache = [
|
|
91
95
|
plugins: [
|
92
96
|
new ExpirationPlugin({
|
93
97
|
maxEntries: 32,
|
94
|
-
maxAgeSeconds: 24 * 60 * 60
|
98
|
+
maxAgeSeconds: 24 * 60 * 60,
|
99
|
+
maxAgeFrom: "last-used"
|
95
100
|
})
|
96
101
|
]
|
97
102
|
})
|
@@ -103,7 +108,8 @@ const defaultCache = [
|
|
103
108
|
plugins: [
|
104
109
|
new ExpirationPlugin({
|
105
110
|
maxEntries: 32,
|
106
|
-
maxAgeSeconds: 24 * 60 * 60
|
111
|
+
maxAgeSeconds: 24 * 60 * 60,
|
112
|
+
maxAgeFrom: "last-used"
|
107
113
|
})
|
108
114
|
]
|
109
115
|
})
|
@@ -115,7 +121,8 @@ const defaultCache = [
|
|
115
121
|
plugins: [
|
116
122
|
new ExpirationPlugin({
|
117
123
|
maxEntries: 32,
|
118
|
-
maxAgeSeconds: 24 * 60 * 60
|
124
|
+
maxAgeSeconds: 24 * 60 * 60,
|
125
|
+
maxAgeFrom: "last-used"
|
119
126
|
})
|
120
127
|
]
|
121
128
|
})
|
@@ -128,7 +135,8 @@ const defaultCache = [
|
|
128
135
|
plugins: [
|
129
136
|
new ExpirationPlugin({
|
130
137
|
maxEntries: 16,
|
131
|
-
maxAgeSeconds: 24 * 60 * 60
|
138
|
+
maxAgeSeconds: 24 * 60 * 60,
|
139
|
+
maxAgeFrom: "last-used"
|
132
140
|
})
|
133
141
|
],
|
134
142
|
networkTimeoutSeconds: 10
|
@@ -141,7 +149,8 @@ const defaultCache = [
|
|
141
149
|
plugins: [
|
142
150
|
new ExpirationPlugin({
|
143
151
|
maxEntries: 32,
|
144
|
-
maxAgeSeconds: 24 * 60 * 60
|
152
|
+
maxAgeSeconds: 24 * 60 * 60,
|
153
|
+
maxAgeFrom: "last-used"
|
145
154
|
})
|
146
155
|
],
|
147
156
|
networkTimeoutSeconds: 10
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@serwist/svelte",
|
3
|
-
"version": "9.0.0-preview.
|
3
|
+
"version": "9.0.0-preview.16",
|
4
4
|
"type": "module",
|
5
5
|
"description": "A module that complements SvelteKit's built-in service worker support.",
|
6
6
|
"files": [
|
@@ -40,21 +40,21 @@
|
|
40
40
|
"./package.json": "./package.json"
|
41
41
|
},
|
42
42
|
"dependencies": {
|
43
|
-
"@serwist/core": "9.0.0-preview.
|
44
|
-
"@serwist/expiration": "9.0.0-preview.
|
45
|
-
"@serwist/strategies": "9.0.0-preview.
|
43
|
+
"@serwist/core": "9.0.0-preview.16",
|
44
|
+
"@serwist/expiration": "9.0.0-preview.16",
|
45
|
+
"@serwist/strategies": "9.0.0-preview.16"
|
46
46
|
},
|
47
47
|
"devDependencies": {
|
48
|
-
"@sveltejs/kit": "2.5.
|
48
|
+
"@sveltejs/kit": "2.5.4",
|
49
49
|
"rollup": "4.13.0",
|
50
|
-
"@serwist/constants": "9.0.0-preview.
|
51
|
-
"@serwist/precaching": "9.0.0-preview.
|
52
|
-
"@serwist/sw": "9.0.0-preview.
|
50
|
+
"@serwist/constants": "9.0.0-preview.16",
|
51
|
+
"@serwist/precaching": "9.0.0-preview.16",
|
52
|
+
"@serwist/sw": "9.0.0-preview.16"
|
53
53
|
},
|
54
54
|
"peerDependencies": {
|
55
55
|
"@sveltejs/kit": ">=2.0.0",
|
56
56
|
"typescript": ">=5.0.0",
|
57
|
-
"@serwist/sw": "9.0.0-preview.
|
57
|
+
"@serwist/sw": "9.0.0-preview.16"
|
58
58
|
},
|
59
59
|
"peerDependenciesMeta": {
|
60
60
|
"@serwist/sw": {
|
package/src/index.worker.ts
CHANGED
@@ -4,6 +4,7 @@ import type { PrecacheEntry } from "@serwist/precaching";
|
|
4
4
|
import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from "@serwist/strategies";
|
5
5
|
import type { RuntimeCaching } from "@serwist/sw";
|
6
6
|
|
7
|
+
import { dev } from "$app/environment";
|
7
8
|
import {
|
8
9
|
base as basePath,
|
9
10
|
build as immutableAssets,
|
@@ -122,104 +123,120 @@ export const getPrecacheManifest = ({
|
|
122
123
|
|
123
124
|
export const defaultIgnoreUrlParameters = [/^x-sveltekit-invalidated$/];
|
124
125
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
126
|
+
/**
|
127
|
+
* The default, recommended list of caching strategies for applications
|
128
|
+
* built with SvelteKit.
|
129
|
+
*
|
130
|
+
* @see https://serwist.pages.dev/docs/svelte/worker-exports#default-cache
|
131
|
+
*/
|
132
|
+
export const defaultCache: RuntimeCaching[] = dev
|
133
|
+
? []
|
134
|
+
: [
|
135
|
+
{
|
136
|
+
matcher: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,
|
137
|
+
handler: new CacheFirst({
|
138
|
+
cacheName: "google-fonts",
|
139
|
+
plugins: [
|
140
|
+
new ExpirationPlugin({
|
141
|
+
maxEntries: 4,
|
142
|
+
maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days
|
143
|
+
maxAgeFrom: "last-used",
|
144
|
+
}),
|
145
|
+
],
|
134
146
|
}),
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
147
|
+
},
|
148
|
+
{
|
149
|
+
matcher: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
|
150
|
+
handler: new StaleWhileRevalidate({
|
151
|
+
cacheName: "static-font-assets",
|
152
|
+
plugins: [
|
153
|
+
new ExpirationPlugin({
|
154
|
+
maxEntries: 4,
|
155
|
+
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
|
156
|
+
maxAgeFrom: "last-used",
|
157
|
+
}),
|
158
|
+
],
|
146
159
|
}),
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
160
|
+
},
|
161
|
+
{
|
162
|
+
matcher: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
|
163
|
+
handler: new StaleWhileRevalidate({
|
164
|
+
cacheName: "static-image-assets",
|
165
|
+
plugins: [
|
166
|
+
new ExpirationPlugin({
|
167
|
+
maxEntries: 64,
|
168
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
169
|
+
maxAgeFrom: "last-used",
|
170
|
+
}),
|
171
|
+
],
|
158
172
|
}),
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
173
|
+
},
|
174
|
+
{
|
175
|
+
matcher: /\.(?:js)$/i,
|
176
|
+
handler: new StaleWhileRevalidate({
|
177
|
+
cacheName: "static-js-assets",
|
178
|
+
plugins: [
|
179
|
+
new ExpirationPlugin({
|
180
|
+
maxEntries: 32,
|
181
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
182
|
+
maxAgeFrom: "last-used",
|
183
|
+
}),
|
184
|
+
],
|
170
185
|
}),
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
186
|
+
},
|
187
|
+
{
|
188
|
+
matcher: /\.(?:css|less)$/i,
|
189
|
+
handler: new StaleWhileRevalidate({
|
190
|
+
cacheName: "static-style-assets",
|
191
|
+
plugins: [
|
192
|
+
new ExpirationPlugin({
|
193
|
+
maxEntries: 32,
|
194
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
195
|
+
maxAgeFrom: "last-used",
|
196
|
+
}),
|
197
|
+
],
|
182
198
|
}),
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
199
|
+
},
|
200
|
+
{
|
201
|
+
matcher: /\.(?:json|xml|csv)$/i,
|
202
|
+
handler: new NetworkFirst({
|
203
|
+
cacheName: "static-data-assets",
|
204
|
+
plugins: [
|
205
|
+
new ExpirationPlugin({
|
206
|
+
maxEntries: 32,
|
207
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
208
|
+
maxAgeFrom: "last-used",
|
209
|
+
}),
|
210
|
+
],
|
194
211
|
}),
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
212
|
+
},
|
213
|
+
{
|
214
|
+
matcher: /\/api\/.*$/i,
|
215
|
+
method: "GET",
|
216
|
+
handler: new NetworkFirst({
|
217
|
+
cacheName: "apis",
|
218
|
+
plugins: [
|
219
|
+
new ExpirationPlugin({
|
220
|
+
maxEntries: 16,
|
221
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
222
|
+
maxAgeFrom: "last-used",
|
223
|
+
}),
|
224
|
+
],
|
225
|
+
networkTimeoutSeconds: 10, // fallback to cache if API does not response within 10 seconds
|
207
226
|
}),
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
227
|
+
},
|
228
|
+
{
|
229
|
+
matcher: /.*/i,
|
230
|
+
handler: new NetworkFirst({
|
231
|
+
cacheName: "others",
|
232
|
+
plugins: [
|
233
|
+
new ExpirationPlugin({
|
234
|
+
maxEntries: 32,
|
235
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
236
|
+
maxAgeFrom: "last-used",
|
237
|
+
}),
|
238
|
+
],
|
239
|
+
networkTimeoutSeconds: 10,
|
220
240
|
}),
|
221
|
-
|
222
|
-
|
223
|
-
}),
|
224
|
-
},
|
225
|
-
];
|
241
|
+
},
|
242
|
+
];
|