oeffisearch/client/service-worker.js
2020-02-07 14:09:42 +01:00

92 lines
2.4 KiB
JavaScript

'use strict';
const CACHE = 'cache-v34';
let preCache = [
'./img/product_bus_grey.svg',
'./img/product_cablecar_color.svg',
'./img/product_cablecar_grey.svg',
'./img/product_call_color.svg',
'./img/product_call_grey.svg',
'./img/product_ferry_color.svg',
'./img/product_ferry_grey.svg',
'./img/product_highspeed_color.svg',
'./img/product_highspeed_grey.svg',
'./img/product_suburban_color.svg',
'./img/product_suburban_grey.svg',
'./img/product_subway_color.svg',
'./img/product_subway_grey.svg',
'./img/product_train_color.svg',
'./img/product_train_grey.svg',
'./img/product_bus_color.svg',
'./img/product_tram_grey.svg',
'./img/product_tram_color.svg',
'./img/back.svg',
'./img/baseline-beenhere-24px.svg',
'./img/baseline-departure_board-24px.svg',
'./img/baseline-directions-24px.svg',
'./img/baseline-directions-24px_white.svg',
'./img/baseline-directions_walk-24px.svg',
'./img/baseline-expand_more-24px.svg',
'./img/baseline-import_export-24px.svg',
'./img/baseline-navigation-24px.svg',
'./img/baseline-place-24px.svg',
'./img/baseline-settings-20px.svg',
'./ing/baseline-swap_vert-24px.svg',
'./img/baseline-refresh-24px.svg',
'./img/ba8064fd767ceaa170589aa3dd11e58e.jpg',
'./img/favicon-16x16.png',
'./img/favicon-32x32.png',
'./img/favicon-64x64.png',
'./img/favicon-512x512.png',
'./img/apple-touch-icon.png',
'./js/api.js',
'./js/canvas.js',
'./js/journeysView.js',
'./js/journeyView.js',
'./js/searchView.js',
'./js/settingsView.js',
'./js/app_functions.js',
'./js/helpers.js',
'./js/app.js',
'./js/router.js',
'./js/overlays.js',
'./css/product_selector.css',
'./css/style.css',
'./manifest.json',
'./index.html',
'./'
];
self.addEventListener('install', function (evt) {
self.skipWaiting();
evt.waitUntil(caches.open(CACHE).then(function (cache) {
cache.addAll(preCache);
}));
});
self.addEventListener('fetch', function (evt) {
evt.respondWith(fromCache(evt.request).then(function (match) {
if (match) {
return match;
} else {
return fetch(evt.request);
}
}));
});
self.addEventListener('activate', function (event) {
event.waitUntil(clients.claim());
event.waitUntil(clients.claim().then(function () {
return caches.keys().then(function (cacheNames) {
return Promise.all(cacheNames.filter(c => c !== CACHE).map(c => caches.delete(c)));
});
}));
});
function fromCache (request) {
return caches.open(CACHE).then(function (cache) {
return cache.match(request);
});
}