blob: a718ec4c73332334b982b2a8607c01c297963831 [file] [log] [blame]
Adrià Vilanova Martínezf4c66722021-10-20 21:53:30 +02001var CACHE_NAME = 'linia-cache-v1.0.3';
avm9996399bb77c2020-01-27 03:15:08 +01002var 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',
avm9996309a08862020-03-21 17:46:25 +01009 'css/views/l9n.css',
10 'offline.html'
avm9996399bb77c2020-01-27 03:15:08 +010011];
12
13self.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
22self.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);
avm9996309a08862020-03-21 17:46:25 +010038 return caches.match('offline.html');
avm9996399bb77c2020-01-27 03:15:08 +010039 })
40 );
41});