avm99963 | 6a5bb40 | 2021-03-01 23:25:37 +0100 | [diff] [blame^] | 1 | var CACHE_NAME = 'all-v1.1.2'; |
avm99963 | 1ca663e | 2020-12-17 19:34:22 +0100 | [diff] [blame] | 2 | var urlsToCache = [ |
| 3 | '/', |
| 4 | '/css/styles.css', |
| 5 | '/img/logo.svg', |
avm99963 | 6a5bb40 | 2021-03-01 23:25:37 +0100 | [diff] [blame^] | 6 | '/img/logo-ciba.png', |
avm99963 | 1ca663e | 2020-12-17 19:34:22 +0100 | [diff] [blame] | 7 | '/js/script.js', |
| 8 | '/concerts/nadal2020joves.json', |
| 9 | '/concerts/nadal2020nens.json', |
avm99963 | c26d16b | 2021-02-28 00:58:56 +0100 | [diff] [blame] | 10 | '/concerts/ciba2021.json', |
avm99963 | 1ca663e | 2020-12-17 19:34:22 +0100 | [diff] [blame] | 11 | ]; |
| 12 | |
| 13 | self.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 | |
avm99963 | 6a5bb40 | 2021-03-01 23:25:37 +0100 | [diff] [blame^] | 23 | self.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 | |
avm99963 | 1ca663e | 2020-12-17 19:34:22 +0100 | [diff] [blame] | 34 | self.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 | }); |