2023-04-01 08:43:07 +02:00
|
|
|
importScripts('https://cdn.jsdelivr.net/npm/workbox-sw@6.5.4/build/workbox-sw.js');
|
2022-07-30 21:12:33 +02:00
|
|
|
|
2023-04-07 11:44:33 +02:00
|
|
|
self.addEventListener("message", event => {
|
2022-07-30 21:12:33 +02:00
|
|
|
if (event.data && event.data.type === "SKIP_WAITING") {
|
|
|
|
self.skipWaiting();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-04-01 08:43:07 +02:00
|
|
|
workbox.routing.registerRoute(
|
2024-01-12 10:27:25 +01:00
|
|
|
({ url }) => !url.pathname.startsWith('/_img/canvas/'),
|
|
|
|
// `workbox.strategies.StaleWhileRevalidate` is used to reduce server contact.
|
|
|
|
// Change to `workbox.strategies.NetworkFirst` when updating is required.
|
2023-04-01 08:43:07 +02:00
|
|
|
new workbox.strategies.NetworkFirst({
|
|
|
|
cacheName: "main",
|
|
|
|
plugins: [
|
|
|
|
new workbox.backgroundSync.BackgroundSyncPlugin(
|
2023-04-01 10:56:52 +02:00
|
|
|
"main-queue", {
|
2024-01-12 10:27:25 +01:00
|
|
|
maxRetentionTime: 4 * 7 * 24 * 60 // 4 weeks (in minutes)
|
2023-04-01 08:43:07 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
]
|
|
|
|
})
|
|
|
|
);
|
2022-07-30 21:12:33 +02:00
|
|
|
|
|
|
|
workbox.routing.registerRoute(
|
2023-04-01 08:43:07 +02:00
|
|
|
({ url }) => url.pathname.startsWith('/_img/canvas/'),
|
2024-01-12 10:27:25 +01:00
|
|
|
// `workbox.strategies.CacheFirst` is used to minimize server contact, due to their size.
|
|
|
|
// Change to `workbox.strategies.StateWhileRevalidate` when updating is required.
|
2023-04-01 08:43:07 +02:00
|
|
|
new workbox.strategies.CacheFirst({
|
2024-01-12 10:27:25 +01:00
|
|
|
cacheName: "canvas"
|
2022-07-30 21:12:33 +02:00
|
|
|
})
|
|
|
|
);
|