@julien-lin/universal-pwa-templates 1.2.4 → 1.2.5
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.cjs +484 -474
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +484 -474
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -34,497 +34,507 @@ module.exports = __toCommonJS(index_exports);
|
|
|
34
34
|
|
|
35
35
|
// src/service-worker/static.ts
|
|
36
36
|
var staticServiceWorkerTemplate = `
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
37
|
+
// Load Workbox from CDN
|
|
38
|
+
importScripts('https://storage.googleapis.com/workbox-cdn/releases/7.4.0/workbox-sw.js')
|
|
39
|
+
|
|
40
|
+
// Ensure Workbox is loaded
|
|
41
|
+
if (typeof workbox !== 'undefined') {
|
|
42
|
+
// Precache des assets statiques
|
|
43
|
+
workbox.precaching.precacheAndRoute(self.__WB_MANIFEST)
|
|
44
|
+
|
|
45
|
+
// CacheFirst pour images, fonts, CSS, JS
|
|
46
|
+
workbox.routing.registerRoute(
|
|
47
|
+
({ request }) => request.destination === 'image',
|
|
48
|
+
new workbox.strategies.CacheFirst({
|
|
49
|
+
cacheName: 'images-cache',
|
|
50
|
+
plugins: [
|
|
51
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
52
|
+
statuses: [0, 200],
|
|
53
|
+
}),
|
|
54
|
+
new workbox.expiration.ExpirationPlugin({
|
|
55
|
+
maxEntries: 60,
|
|
56
|
+
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
|
|
57
|
+
}),
|
|
58
|
+
],
|
|
59
|
+
})
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
workbox.routing.registerRoute(
|
|
63
|
+
({ request }) => request.destination === 'font',
|
|
64
|
+
new workbox.strategies.CacheFirst({
|
|
65
|
+
cacheName: 'fonts-cache',
|
|
66
|
+
plugins: [
|
|
67
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
68
|
+
statuses: [0, 200],
|
|
69
|
+
}),
|
|
70
|
+
new workbox.expiration.ExpirationPlugin({
|
|
71
|
+
maxEntries: 30,
|
|
72
|
+
maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an
|
|
73
|
+
}),
|
|
74
|
+
],
|
|
75
|
+
})
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
workbox.routing.registerRoute(
|
|
79
|
+
({ request }) => request.destination === 'style' || request.destination === 'script',
|
|
80
|
+
new workbox.strategies.CacheFirst({
|
|
81
|
+
cacheName: 'assets-cache',
|
|
82
|
+
plugins: [
|
|
83
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
84
|
+
statuses: [0, 200],
|
|
85
|
+
}),
|
|
86
|
+
new workbox.expiration.ExpirationPlugin({
|
|
87
|
+
maxEntries: 50,
|
|
88
|
+
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours
|
|
89
|
+
}),
|
|
90
|
+
],
|
|
91
|
+
})
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
// NetworkFirst pour les pages HTML
|
|
95
|
+
workbox.routing.registerRoute(
|
|
96
|
+
({ request }) => request.mode === 'navigate',
|
|
97
|
+
new workbox.strategies.NetworkFirst({
|
|
98
|
+
cacheName: 'pages-cache',
|
|
99
|
+
plugins: [
|
|
100
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
101
|
+
statuses: [0, 200],
|
|
102
|
+
}),
|
|
103
|
+
new workbox.expiration.ExpirationPlugin({
|
|
104
|
+
maxEntries: 50,
|
|
105
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 heures
|
|
106
|
+
}),
|
|
107
|
+
],
|
|
108
|
+
})
|
|
109
|
+
)
|
|
110
|
+
} else {
|
|
111
|
+
console.error('Workbox could not be loaded.')
|
|
112
|
+
}
|
|
111
113
|
`;
|
|
112
114
|
|
|
113
115
|
// src/service-worker/spa.ts
|
|
114
116
|
var spaServiceWorkerTemplate = `
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
denylist: [/^\\/api/, /^\\/_/],
|
|
129
|
-
})
|
|
130
|
-
registerRoute(navigationRoute)
|
|
131
|
-
|
|
132
|
-
// CacheFirst pour images, fonts
|
|
133
|
-
registerRoute(
|
|
134
|
-
({ request }) => request.destination === 'image',
|
|
135
|
-
new CacheFirst({
|
|
136
|
-
cacheName: 'images-cache',
|
|
137
|
-
plugins: [
|
|
138
|
-
new CacheableResponsePlugin({
|
|
139
|
-
statuses: [0, 200],
|
|
140
|
-
}),
|
|
141
|
-
new ExpirationPlugin({
|
|
142
|
-
maxEntries: 60,
|
|
143
|
-
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
|
|
144
|
-
}),
|
|
145
|
-
],
|
|
146
|
-
})
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
registerRoute(
|
|
150
|
-
({ request }) => request.destination === 'font',
|
|
151
|
-
new CacheFirst({
|
|
152
|
-
cacheName: 'fonts-cache',
|
|
153
|
-
plugins: [
|
|
154
|
-
new CacheableResponsePlugin({
|
|
155
|
-
statuses: [0, 200],
|
|
156
|
-
}),
|
|
157
|
-
new ExpirationPlugin({
|
|
158
|
-
maxEntries: 30,
|
|
159
|
-
maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an
|
|
160
|
-
}),
|
|
161
|
-
],
|
|
162
|
-
})
|
|
163
|
-
)
|
|
164
|
-
|
|
165
|
-
// StaleWhileRevalidate for CSS/JS (background update)
|
|
166
|
-
registerRoute(
|
|
167
|
-
({ request }) => request.destination === 'style' || request.destination === 'script',
|
|
168
|
-
new StaleWhileRevalidate({
|
|
169
|
-
cacheName: 'assets-cache',
|
|
170
|
-
plugins: [
|
|
171
|
-
new CacheableResponsePlugin({
|
|
172
|
-
statuses: [0, 200],
|
|
173
|
-
}),
|
|
174
|
-
new ExpirationPlugin({
|
|
175
|
-
maxEntries: 50,
|
|
176
|
-
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours
|
|
177
|
-
}),
|
|
178
|
-
],
|
|
179
|
-
})
|
|
180
|
-
)
|
|
181
|
-
|
|
182
|
-
// NetworkFirst pour les appels API
|
|
183
|
-
registerRoute(
|
|
184
|
-
({ url }) => url.pathname.startsWith('/api/'),
|
|
185
|
-
new NetworkFirst({
|
|
186
|
-
cacheName: 'api-cache',
|
|
187
|
-
plugins: [
|
|
188
|
-
new CacheableResponsePlugin({
|
|
189
|
-
statuses: [0, 200],
|
|
190
|
-
}),
|
|
191
|
-
new ExpirationPlugin({
|
|
192
|
-
maxEntries: 50,
|
|
193
|
-
maxAgeSeconds: 5 * 60, // 5 minutes
|
|
194
|
-
}),
|
|
195
|
-
],
|
|
117
|
+
// Load Workbox from CDN
|
|
118
|
+
importScripts('https://storage.googleapis.com/workbox-cdn/releases/7.4.0/workbox-sw.js')
|
|
119
|
+
|
|
120
|
+
// Ensure Workbox is loaded
|
|
121
|
+
if (typeof workbox !== 'undefined') {
|
|
122
|
+
// Precache des assets statiques
|
|
123
|
+
workbox.precaching.precacheAndRoute(self.__WB_MANIFEST)
|
|
124
|
+
|
|
125
|
+
// Navigation route pour SPA (toutes les navigations vers index.html)
|
|
126
|
+
const navigationHandler = workbox.precaching.createHandlerBoundToURL('/index.html')
|
|
127
|
+
const navigationRoute = new workbox.routing.NavigationRoute(navigationHandler, {
|
|
128
|
+
allowlist: [/^\\//],
|
|
129
|
+
denylist: [/^\\/api/, /^\\/_/],
|
|
196
130
|
})
|
|
197
|
-
)
|
|
131
|
+
workbox.routing.registerRoute(navigationRoute)
|
|
132
|
+
|
|
133
|
+
// CacheFirst pour images, fonts
|
|
134
|
+
workbox.routing.registerRoute(
|
|
135
|
+
({ request }) => request.destination === 'image',
|
|
136
|
+
new workbox.strategies.CacheFirst({
|
|
137
|
+
cacheName: 'images-cache',
|
|
138
|
+
plugins: [
|
|
139
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
140
|
+
statuses: [0, 200],
|
|
141
|
+
}),
|
|
142
|
+
new workbox.expiration.ExpirationPlugin({
|
|
143
|
+
maxEntries: 60,
|
|
144
|
+
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
|
|
145
|
+
}),
|
|
146
|
+
],
|
|
147
|
+
})
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
workbox.routing.registerRoute(
|
|
151
|
+
({ request }) => request.destination === 'font',
|
|
152
|
+
new workbox.strategies.CacheFirst({
|
|
153
|
+
cacheName: 'fonts-cache',
|
|
154
|
+
plugins: [
|
|
155
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
156
|
+
statuses: [0, 200],
|
|
157
|
+
}),
|
|
158
|
+
new workbox.expiration.ExpirationPlugin({
|
|
159
|
+
maxEntries: 30,
|
|
160
|
+
maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an
|
|
161
|
+
}),
|
|
162
|
+
],
|
|
163
|
+
})
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
// StaleWhileRevalidate for CSS/JS (background update)
|
|
167
|
+
workbox.routing.registerRoute(
|
|
168
|
+
({ request }) => request.destination === 'style' || request.destination === 'script',
|
|
169
|
+
new workbox.strategies.StaleWhileRevalidate({
|
|
170
|
+
cacheName: 'assets-cache',
|
|
171
|
+
plugins: [
|
|
172
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
173
|
+
statuses: [0, 200],
|
|
174
|
+
}),
|
|
175
|
+
new workbox.expiration.ExpirationPlugin({
|
|
176
|
+
maxEntries: 50,
|
|
177
|
+
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours
|
|
178
|
+
}),
|
|
179
|
+
],
|
|
180
|
+
})
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
// NetworkFirst pour les appels API
|
|
184
|
+
workbox.routing.registerRoute(
|
|
185
|
+
({ url }) => url.pathname.startsWith('/api/'),
|
|
186
|
+
new workbox.strategies.NetworkFirst({
|
|
187
|
+
cacheName: 'api-cache',
|
|
188
|
+
plugins: [
|
|
189
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
190
|
+
statuses: [0, 200],
|
|
191
|
+
}),
|
|
192
|
+
new workbox.expiration.ExpirationPlugin({
|
|
193
|
+
maxEntries: 50,
|
|
194
|
+
maxAgeSeconds: 5 * 60, // 5 minutes
|
|
195
|
+
}),
|
|
196
|
+
],
|
|
197
|
+
})
|
|
198
|
+
)
|
|
199
|
+
} else {
|
|
200
|
+
console.error('Workbox could not be loaded.')
|
|
201
|
+
}
|
|
198
202
|
`;
|
|
199
203
|
|
|
200
204
|
// src/service-worker/ssr.ts
|
|
201
205
|
var ssrServiceWorkerTemplate = `
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
206
|
+
// Load Workbox from CDN
|
|
207
|
+
importScripts('https://storage.googleapis.com/workbox-cdn/releases/7.4.0/workbox-sw.js')
|
|
208
|
+
|
|
209
|
+
// Ensure Workbox is loaded
|
|
210
|
+
if (typeof workbox !== 'undefined') {
|
|
211
|
+
// Precache des assets statiques critiques
|
|
212
|
+
workbox.precaching.precacheAndRoute(self.__WB_MANIFEST)
|
|
213
|
+
|
|
214
|
+
// NetworkFirst for HTML pages (server priority for fresh content)
|
|
215
|
+
workbox.routing.registerRoute(
|
|
216
|
+
({ request }) => request.mode === 'navigate',
|
|
217
|
+
new workbox.strategies.NetworkFirst({
|
|
218
|
+
cacheName: 'pages-cache',
|
|
219
|
+
plugins: [
|
|
220
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
221
|
+
statuses: [0, 200],
|
|
222
|
+
}),
|
|
223
|
+
new workbox.expiration.ExpirationPlugin({
|
|
224
|
+
maxEntries: 50,
|
|
225
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 heures
|
|
226
|
+
}),
|
|
227
|
+
],
|
|
228
|
+
networkTimeoutSeconds: 3, // Timeout de 3 secondes
|
|
229
|
+
})
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
// CacheFirst pour images, fonts
|
|
233
|
+
workbox.routing.registerRoute(
|
|
234
|
+
({ request }) => request.destination === 'image',
|
|
235
|
+
new workbox.strategies.CacheFirst({
|
|
236
|
+
cacheName: 'images-cache',
|
|
237
|
+
plugins: [
|
|
238
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
239
|
+
statuses: [0, 200],
|
|
240
|
+
}),
|
|
241
|
+
new workbox.expiration.ExpirationPlugin({
|
|
242
|
+
maxEntries: 60,
|
|
243
|
+
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
|
|
244
|
+
}),
|
|
245
|
+
],
|
|
246
|
+
})
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
workbox.routing.registerRoute(
|
|
250
|
+
({ request }) => request.destination === 'font',
|
|
251
|
+
new workbox.strategies.CacheFirst({
|
|
252
|
+
cacheName: 'fonts-cache',
|
|
253
|
+
plugins: [
|
|
254
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
255
|
+
statuses: [0, 200],
|
|
256
|
+
}),
|
|
257
|
+
new workbox.expiration.ExpirationPlugin({
|
|
258
|
+
maxEntries: 30,
|
|
259
|
+
maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an
|
|
260
|
+
}),
|
|
261
|
+
],
|
|
262
|
+
})
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
// StaleWhileRevalidate pour CSS/JS
|
|
266
|
+
workbox.routing.registerRoute(
|
|
267
|
+
({ request }) => request.destination === 'style' || request.destination === 'script',
|
|
268
|
+
new workbox.strategies.StaleWhileRevalidate({
|
|
269
|
+
cacheName: 'assets-cache',
|
|
270
|
+
plugins: [
|
|
271
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
272
|
+
statuses: [0, 200],
|
|
273
|
+
}),
|
|
274
|
+
new workbox.expiration.ExpirationPlugin({
|
|
275
|
+
maxEntries: 50,
|
|
276
|
+
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours
|
|
277
|
+
}),
|
|
278
|
+
],
|
|
279
|
+
})
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
// NetworkFirst pour les appels API
|
|
283
|
+
workbox.routing.registerRoute(
|
|
284
|
+
({ url }) => url.pathname.startsWith('/api/') || url.pathname.startsWith('/graphql'),
|
|
285
|
+
new workbox.strategies.NetworkFirst({
|
|
286
|
+
cacheName: 'api-cache',
|
|
287
|
+
plugins: [
|
|
288
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
289
|
+
statuses: [0, 200],
|
|
290
|
+
}),
|
|
291
|
+
new workbox.expiration.ExpirationPlugin({
|
|
292
|
+
maxEntries: 50,
|
|
293
|
+
maxAgeSeconds: 5 * 60, // 5 minutes
|
|
294
|
+
}),
|
|
295
|
+
],
|
|
296
|
+
networkTimeoutSeconds: 3,
|
|
297
|
+
})
|
|
298
|
+
)
|
|
299
|
+
} else {
|
|
300
|
+
console.error('Workbox could not be loaded.')
|
|
301
|
+
}
|
|
296
302
|
`;
|
|
297
303
|
|
|
298
304
|
// src/service-worker/wordpress.ts
|
|
299
305
|
var wordpressServiceWorkerTemplate = `
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
306
|
+
// Load Workbox from CDN
|
|
307
|
+
importScripts('https://storage.googleapis.com/workbox-cdn/releases/7.4.0/workbox-sw.js')
|
|
308
|
+
|
|
309
|
+
// Ensure Workbox is loaded
|
|
310
|
+
if (typeof workbox !== 'undefined') {
|
|
311
|
+
// Precache des assets statiques
|
|
312
|
+
workbox.precaching.precacheAndRoute(self.__WB_MANIFEST)
|
|
313
|
+
|
|
314
|
+
// NetworkFirst for WordPress pages (server priority)
|
|
315
|
+
workbox.routing.registerRoute(
|
|
316
|
+
({ request }) => request.mode === 'navigate',
|
|
317
|
+
new workbox.strategies.NetworkFirst({
|
|
318
|
+
cacheName: 'wp-pages-cache',
|
|
319
|
+
plugins: [
|
|
320
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
321
|
+
statuses: [0, 200],
|
|
322
|
+
}),
|
|
323
|
+
new workbox.expiration.ExpirationPlugin({
|
|
324
|
+
maxEntries: 50,
|
|
325
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 heures
|
|
326
|
+
}),
|
|
327
|
+
],
|
|
328
|
+
networkTimeoutSeconds: 3,
|
|
329
|
+
})
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
// CacheFirst pour les assets WordPress (wp-content)
|
|
333
|
+
workbox.routing.registerRoute(
|
|
334
|
+
({ url }) => url.pathname.includes('/wp-content/'),
|
|
335
|
+
new workbox.strategies.CacheFirst({
|
|
336
|
+
cacheName: 'wp-assets-cache',
|
|
337
|
+
plugins: [
|
|
338
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
339
|
+
statuses: [0, 200],
|
|
340
|
+
}),
|
|
341
|
+
new workbox.expiration.ExpirationPlugin({
|
|
342
|
+
maxEntries: 100,
|
|
343
|
+
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
|
|
344
|
+
}),
|
|
345
|
+
],
|
|
346
|
+
})
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
// CacheFirst pour images
|
|
350
|
+
workbox.routing.registerRoute(
|
|
351
|
+
({ request }) => request.destination === 'image',
|
|
352
|
+
new workbox.strategies.CacheFirst({
|
|
353
|
+
cacheName: 'images-cache',
|
|
354
|
+
plugins: [
|
|
355
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
356
|
+
statuses: [0, 200],
|
|
357
|
+
}),
|
|
358
|
+
new workbox.expiration.ExpirationPlugin({
|
|
359
|
+
maxEntries: 60,
|
|
360
|
+
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
|
|
361
|
+
}),
|
|
362
|
+
],
|
|
363
|
+
})
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
// CacheFirst pour fonts
|
|
367
|
+
workbox.routing.registerRoute(
|
|
368
|
+
({ request }) => request.destination === 'font',
|
|
369
|
+
new workbox.strategies.CacheFirst({
|
|
370
|
+
cacheName: 'fonts-cache',
|
|
371
|
+
plugins: [
|
|
372
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
373
|
+
statuses: [0, 200],
|
|
374
|
+
}),
|
|
375
|
+
new workbox.expiration.ExpirationPlugin({
|
|
376
|
+
maxEntries: 30,
|
|
377
|
+
maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an
|
|
378
|
+
}),
|
|
379
|
+
],
|
|
380
|
+
})
|
|
381
|
+
)
|
|
382
|
+
|
|
383
|
+
// StaleWhileRevalidate pour CSS/JS
|
|
384
|
+
workbox.routing.registerRoute(
|
|
385
|
+
({ request }) => request.destination === 'style' || request.destination === 'script',
|
|
386
|
+
new workbox.strategies.StaleWhileRevalidate({
|
|
387
|
+
cacheName: 'assets-cache',
|
|
388
|
+
plugins: [
|
|
389
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
390
|
+
statuses: [0, 200],
|
|
391
|
+
}),
|
|
392
|
+
new workbox.expiration.ExpirationPlugin({
|
|
393
|
+
maxEntries: 50,
|
|
394
|
+
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours
|
|
395
|
+
}),
|
|
396
|
+
],
|
|
397
|
+
})
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
// NetworkFirst pour wp-admin et wp-json (API REST WordPress)
|
|
401
|
+
workbox.routing.registerRoute(
|
|
402
|
+
({ url }) => url.pathname.startsWith('/wp-admin/') || url.pathname.startsWith('/wp-json/'),
|
|
403
|
+
new workbox.strategies.NetworkFirst({
|
|
404
|
+
cacheName: 'wp-api-cache',
|
|
405
|
+
plugins: [
|
|
406
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
407
|
+
statuses: [0, 200],
|
|
408
|
+
}),
|
|
409
|
+
new workbox.expiration.ExpirationPlugin({
|
|
410
|
+
maxEntries: 30,
|
|
411
|
+
maxAgeSeconds: 5 * 60, // 5 minutes
|
|
412
|
+
}),
|
|
413
|
+
],
|
|
414
|
+
networkTimeoutSeconds: 3,
|
|
415
|
+
})
|
|
416
|
+
)
|
|
417
|
+
} else {
|
|
418
|
+
console.error('Workbox could not be loaded.')
|
|
419
|
+
}
|
|
412
420
|
`;
|
|
413
421
|
|
|
414
422
|
// src/service-worker/php.ts
|
|
415
423
|
var phpServiceWorkerTemplate = `
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
424
|
+
// Load Workbox from CDN
|
|
425
|
+
importScripts('https://storage.googleapis.com/workbox-cdn/releases/7.4.0/workbox-sw.js')
|
|
426
|
+
|
|
427
|
+
// Ensure Workbox is loaded
|
|
428
|
+
if (typeof workbox !== 'undefined') {
|
|
429
|
+
// Precache des assets statiques
|
|
430
|
+
workbox.precaching.precacheAndRoute(self.__WB_MANIFEST)
|
|
431
|
+
|
|
432
|
+
// NetworkFirst for PHP pages (server priority)
|
|
433
|
+
workbox.routing.registerRoute(
|
|
434
|
+
({ request }) => request.mode === 'navigate',
|
|
435
|
+
new workbox.strategies.NetworkFirst({
|
|
436
|
+
cacheName: 'php-pages-cache',
|
|
437
|
+
plugins: [
|
|
438
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
439
|
+
statuses: [0, 200],
|
|
440
|
+
}),
|
|
441
|
+
new workbox.expiration.ExpirationPlugin({
|
|
442
|
+
maxEntries: 50,
|
|
443
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 heures
|
|
444
|
+
}),
|
|
445
|
+
],
|
|
446
|
+
networkTimeoutSeconds: 3,
|
|
447
|
+
})
|
|
448
|
+
)
|
|
449
|
+
|
|
450
|
+
// CacheFirst pour les assets publics (build/, public/)
|
|
451
|
+
workbox.routing.registerRoute(
|
|
452
|
+
({ url }) => url.pathname.startsWith('/build/') || url.pathname.startsWith('/public/'),
|
|
453
|
+
new workbox.strategies.CacheFirst({
|
|
454
|
+
cacheName: 'public-assets-cache',
|
|
455
|
+
plugins: [
|
|
456
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
457
|
+
statuses: [0, 200],
|
|
458
|
+
}),
|
|
459
|
+
new workbox.expiration.ExpirationPlugin({
|
|
460
|
+
maxEntries: 100,
|
|
461
|
+
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
|
|
462
|
+
}),
|
|
463
|
+
],
|
|
464
|
+
})
|
|
465
|
+
)
|
|
466
|
+
|
|
467
|
+
// CacheFirst pour images
|
|
468
|
+
workbox.routing.registerRoute(
|
|
469
|
+
({ request }) => request.destination === 'image',
|
|
470
|
+
new workbox.strategies.CacheFirst({
|
|
471
|
+
cacheName: 'images-cache',
|
|
472
|
+
plugins: [
|
|
473
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
474
|
+
statuses: [0, 200],
|
|
475
|
+
}),
|
|
476
|
+
new workbox.expiration.ExpirationPlugin({
|
|
477
|
+
maxEntries: 60,
|
|
478
|
+
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
|
|
479
|
+
}),
|
|
480
|
+
],
|
|
481
|
+
})
|
|
482
|
+
)
|
|
483
|
+
|
|
484
|
+
// CacheFirst pour fonts
|
|
485
|
+
workbox.routing.registerRoute(
|
|
486
|
+
({ request }) => request.destination === 'font',
|
|
487
|
+
new workbox.strategies.CacheFirst({
|
|
488
|
+
cacheName: 'fonts-cache',
|
|
489
|
+
plugins: [
|
|
490
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
491
|
+
statuses: [0, 200],
|
|
492
|
+
}),
|
|
493
|
+
new workbox.expiration.ExpirationPlugin({
|
|
494
|
+
maxEntries: 30,
|
|
495
|
+
maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an
|
|
496
|
+
}),
|
|
497
|
+
],
|
|
498
|
+
})
|
|
499
|
+
)
|
|
500
|
+
|
|
501
|
+
// StaleWhileRevalidate pour CSS/JS
|
|
502
|
+
workbox.routing.registerRoute(
|
|
503
|
+
({ request }) => request.destination === 'style' || request.destination === 'script',
|
|
504
|
+
new workbox.strategies.StaleWhileRevalidate({
|
|
505
|
+
cacheName: 'assets-cache',
|
|
506
|
+
plugins: [
|
|
507
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
508
|
+
statuses: [0, 200],
|
|
509
|
+
}),
|
|
510
|
+
new workbox.expiration.ExpirationPlugin({
|
|
511
|
+
maxEntries: 50,
|
|
512
|
+
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours
|
|
513
|
+
}),
|
|
514
|
+
],
|
|
515
|
+
})
|
|
516
|
+
)
|
|
517
|
+
|
|
518
|
+
// NetworkFirst pour les routes API
|
|
519
|
+
workbox.routing.registerRoute(
|
|
520
|
+
({ url }) => url.pathname.startsWith('/api/') || url.pathname.startsWith('/graphql'),
|
|
521
|
+
new workbox.strategies.NetworkFirst({
|
|
522
|
+
cacheName: 'api-cache',
|
|
523
|
+
plugins: [
|
|
524
|
+
new workbox.cacheableResponse.CacheableResponsePlugin({
|
|
525
|
+
statuses: [0, 200],
|
|
526
|
+
}),
|
|
527
|
+
new workbox.expiration.ExpirationPlugin({
|
|
528
|
+
maxEntries: 50,
|
|
529
|
+
maxAgeSeconds: 5 * 60, // 5 minutes
|
|
530
|
+
}),
|
|
531
|
+
],
|
|
532
|
+
networkTimeoutSeconds: 3,
|
|
533
|
+
})
|
|
534
|
+
)
|
|
535
|
+
} else {
|
|
536
|
+
console.error('Workbox could not be loaded.')
|
|
537
|
+
}
|
|
528
538
|
`;
|
|
529
539
|
|
|
530
540
|
// src/service-worker/index.ts
|