Adrià Vilanova MartÃnez | f4c6672 | 2021-10-20 21:53:30 +0200 | [diff] [blame] | 1 | var CACHE_NAME = 'linia-cache-v1.0.3'; |
avm99963 | 99bb77c | 2020-01-27 03:15:08 +0100 | [diff] [blame] | 2 | var urlsToCache = [ |
| 3 | '.', |
| 4 | 'js/index.js', |
| 5 | 'css/index.css', |
| 6 | 'info.php?view=0', |
| 7 | 'info.php?view=1', |
| 8 | 'js/views/l9n.js', |
avm99963 | 09a0886 | 2020-03-21 17:46:25 +0100 | [diff] [blame] | 9 | 'css/views/l9n.css', |
| 10 | 'offline.html' |
avm99963 | 99bb77c | 2020-01-27 03:15:08 +0100 | [diff] [blame] | 11 | ]; |
| 12 | |
| 13 | self.addEventListener('install', function(event) { |
| 14 | // Perform install steps |
| 15 | event.waitUntil( |
| 16 | caches.open(CACHE_NAME).then(cache => { |
| 17 | return cache.addAll(urlsToCache); |
| 18 | }) |
| 19 | ); |
| 20 | }); |
| 21 | |
| 22 | self.addEventListener('fetch', function(event) { |
| 23 | var request = event.request; |
| 24 | var url = new URL(request.url); |
| 25 | url.searchParams.delete("station"); |
| 26 | request = new Request(url.toString()); |
| 27 | |
| 28 | event.respondWith( |
| 29 | caches.match(request).then(response => { |
| 30 | // Cache hit - return response |
| 31 | if (response) { |
| 32 | return response; |
| 33 | } |
| 34 | |
| 35 | return fetch(event.request); |
| 36 | }).catch(err => { |
| 37 | console.error(err); |
avm99963 | 09a0886 | 2020-03-21 17:46:25 +0100 | [diff] [blame] | 38 | return caches.match('offline.html'); |
avm99963 | 99bb77c | 2020-01-27 03:15:08 +0100 | [diff] [blame] | 39 | }) |
| 40 | ); |
| 41 | }); |