2022-07-30 21:12:33 +02:00
|
|
|
// This is the "Offline copy of assets" service worker
|
|
|
|
|
|
|
|
const CACHE = "pwabuilder-offline";
|
|
|
|
const QUEUE_NAME = "bgSyncQueue";
|
|
|
|
|
2023-03-18 02:58:34 +01:00
|
|
|
importScripts('https://cdn.jsdelivr.net/npm/workbox-sw@6.5.4/build/workbox-sw.min.js');
|
2022-07-30 21:12:33 +02:00
|
|
|
|
|
|
|
self.addEventListener("message", (event) => {
|
|
|
|
if (event.data && event.data.type === "SKIP_WAITING") {
|
|
|
|
self.skipWaiting();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const bgSyncPlugin = new workbox.backgroundSync.BackgroundSyncPlugin(QUEUE_NAME, {
|
|
|
|
maxRetentionTime: 24 * 60 // Retry for max of 24 Hours (specified in minutes)
|
|
|
|
});
|
|
|
|
|
|
|
|
workbox.routing.registerRoute(
|
|
|
|
new RegExp('/*'),
|
|
|
|
new workbox.strategies.StaleWhileRevalidate({
|
|
|
|
cacheName: CACHE,
|
|
|
|
plugins: [
|
|
|
|
bgSyncPlugin
|
|
|
|
]
|
|
|
|
})
|
|
|
|
);
|