Newer
Older
/* global workbox */ //* allow undefined variable for 'workbox' in this file (because global variable) to avoid eslint error
// 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);
// 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',

Timothee P
committed
plugins: [
new workbox.cacheableResponse.Plugin({
statuses: [0, 200],
}),
],

Timothee P
committed
/^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
}),
],
})
);

Timothee P
committed
workbox.routing.registerRoute(
new RegExp('.*/service=WMS&request=GetMap/.*'),

Timothee P
committed
new workbox.strategies.CacheFirst({

Timothee P
committed
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;
}
});