blob: 90ce2decb8821e5406971ca15f4a6e9d2b1bd81a [file] [log] [blame]
avm999636a5bb402021-03-01 23:25:37 +01001var CACHE_NAME = 'all-v1.1.2';
avm999631ca663e2020-12-17 19:34:22 +01002var urlsToCache = [
3 '/',
4 '/css/styles.css',
5 '/img/logo.svg',
avm999636a5bb402021-03-01 23:25:37 +01006 '/img/logo-ciba.png',
avm999631ca663e2020-12-17 19:34:22 +01007 '/js/script.js',
8 '/concerts/nadal2020joves.json',
9 '/concerts/nadal2020nens.json',
avm99963c26d16b2021-02-28 00:58:56 +010010 '/concerts/ciba2021.json',
avm999631ca663e2020-12-17 19:34:22 +010011];
12
13self.addEventListener('install', event => {
14 self.skipWaiting();
15
16 event.waitUntil(
17 caches.open(CACHE_NAME).then(cache => {
18 return cache.addAll(urlsToCache);
19 })
20 );
21});
22
avm999636a5bb402021-03-01 23:25:37 +010023self.addEventListener('activate', event => {
24 event.waitUntil(
25 caches.keys().then(keyList => {
26 return Promise.all(keyList.map(key => {
27 if (key !== CACHE_NAME)
28 return caches.delete(key);
29 }));
30 })
31 );
32});
33
avm999631ca663e2020-12-17 19:34:22 +010034self.addEventListener('fetch', event => {
35 event.respondWith(
36 caches.match(event.request).then(response => {
37 if (response) return response;
38 return fetch(event.request);
39 })
40 );
41});