/* global workbox */ //* allow undefined variable for 'workbox' in this file (because global variable) to avoid eslint error // custom service-worker.js if (workbox) { // adjust log level for displaying workbox logs //workbox.core.setLogLevel(workbox.core.LOG_LEVELS.debug) // apply precaching. In the built version, the precacheManifest will // be imported using importScripts (as is workbox itself) and we can // precache this. This is all we need for precaching workbox.precaching.precacheAndRoute(self.__precacheManifest); //workbox.core.skipWaiting(); // Make sure to return a specific response for all navigation requests. // Since we have a SPA here, this should be index.html always. // https://stackoverflow.com/questions/49963982/vue-router-history-mode-with-pwa-in-offline-mode workbox.routing.registerNavigationRoute('/geocontrib/index.html', { blacklist: [/\/api/,/\/admin/,/\/media/,/\/cas/], }); workbox.routing.registerRoute( new RegExp('.*/config/config.json'), new workbox.strategies.StaleWhileRevalidate({ cacheName: 'config', }) ); workbox.routing.registerRoute( new RegExp('.*/api/.*'), new workbox.strategies.NetworkFirst({ cacheName: 'api', plugins: [ new workbox.cacheableResponse.Plugin({ statuses: [0, 200], }), ], }) ); workbox.routing.registerRoute( /^https:\/\/[a-zA-Z]\.tile\.openstreetmap\.fr/, new workbox.strategies.CacheFirst({ cacheName: 'osm', plugins: [ new workbox.cacheableResponse.Plugin({ statuses: [0, 200], }), new workbox.expiration.Plugin({ maxAgeSeconds: 60 * 60 * 24 * 365, // maxEntries: 30, pour limiter le nombre d'entrée dans le cache }), ], }) ); workbox.routing.registerRoute( new RegExp('.*/service=WMS&request=GetMap/.*'), new workbox.strategies.CacheFirst({ cacheName: 'wms', plugins: [ new workbox.cacheableResponse.Plugin({ statuses: [0, 200], }), new workbox.expiration.Plugin({ maxAgeSeconds: 60 * 60 * 24 * 365, // maxEntries: 30, pour limiter le nombre d'entrée dans le cache }), ], }) ); } // This code listens for the user's confirmation to update the app. self.addEventListener('message', (e) => { if (!e.data) { return; } //console.log(e.data); switch (e.data.type) { case 'SKIP_WAITING': self.skipWaiting(); break; default: // NOOP break; } });