atlas/web/sw.js

37 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-07-30 21:12:33 +02:00
// This is the "Offline copy of assets" service worker
importScripts('https://cdn.jsdelivr.net/npm/workbox-sw@6.5.4/build/workbox-sw.js');
2022-07-30 21:12:33 +02:00
self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});
workbox.routing.registerRoute(
2023-04-01 10:56:52 +02:00
({ url }) => {!url.pathname.startsWith('/_img/canvas/')},
new workbox.strategies.NetworkFirst({
cacheName: "main",
plugins: [
new workbox.backgroundSync.BackgroundSyncPlugin(
2023-04-01 10:56:52 +02:00
"main-queue", {
maxRetentionTime: 24 * 60 // 24 hours (in minutes)
}
)
]
})
);
2022-07-30 21:12:33 +02:00
workbox.routing.registerRoute(
({ url }) => url.pathname.startsWith('/_img/canvas/'),
new workbox.strategies.CacheFirst({
cacheName: "canvas",
2022-07-30 21:12:33 +02:00
plugins: [
2023-04-01 10:56:52 +02:00
new workbox.backgroundSync.BackgroundSyncPlugin(
"canvas-queue", {
maxRetentionTime: 4 * 7 * 24 * 60 // 4 weeks (in minutes)
}
)
2022-07-30 21:12:33 +02:00
]
})
);