avm99963 | 99bb77c | 2020-01-27 03:15:08 +0100 | [diff] [blame] | 1 | var CACHE_NAME = 'linia-cache-v1'; |
| 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', |
| 9 | 'css/views/l9n.css' |
| 10 | ]; |
| 11 | |
| 12 | self.addEventListener('install', function(event) { |
| 13 | // Perform install steps |
| 14 | event.waitUntil( |
| 15 | caches.open(CACHE_NAME).then(cache => { |
| 16 | return cache.addAll(urlsToCache); |
| 17 | }) |
| 18 | ); |
| 19 | }); |
| 20 | |
| 21 | self.addEventListener('fetch', function(event) { |
| 22 | var request = event.request; |
| 23 | var url = new URL(request.url); |
| 24 | url.searchParams.delete("station"); |
| 25 | request = new Request(url.toString()); |
| 26 | |
| 27 | event.respondWith( |
| 28 | caches.match(request).then(response => { |
| 29 | // Cache hit - return response |
| 30 | if (response) { |
| 31 | return response; |
| 32 | } |
| 33 | |
| 34 | return fetch(event.request); |
| 35 | }).catch(err => { |
| 36 | console.error(err); |
| 37 | }) |
| 38 | ); |
| 39 | }); |