mirror of
https://github.com/placeAtlas/atlas.git
synced 2024-11-13 21:41:54 +01:00
26 lines
725 B
JavaScript
26 lines
725 B
JavaScript
|
// This is the "Offline copy of assets" service worker
|
||
|
|
||
|
const CACHE = "pwabuilder-offline";
|
||
|
const QUEUE_NAME = "bgSyncQueue";
|
||
|
|
||
|
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js');
|
||
|
|
||
|
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
|
||
|
]
|
||
|
})
|
||
|
);
|