aboutsummaryrefslogtreecommitdiffstats
path: root/sworker.js
blob: 2eb553db9d1779bbcb71056ef3c9edb5293ad109 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
console.log('I AM ALIVE!!!');

this.addEventListener('install', function(ev) {
  console.log('AND I INSTALLED!!!1');
  ev.waitUntil(
    caches.open("v1").then(function(cache) {
      return cache.addAll([
        'index.html',
        'activePage.js',
        'activePage.js.map',
        'config.js',
        'config.js.map',
        'hesla.js',
        'hesla.js.map',
        'hesla.webapp',
        'require.js',
        'favicon.ico',
        'icon-128.png',
        'icon-30.png',
        'icon-60.png',
        'index_de.html',
        'index.html',
        'require.js',
        'screen.css'
      ]);
    })
 );
});

this.addEventListener('fetch', function(event) {
  event.respondWith(
    caches.match(event.request).then(function(pro) {
      console.log('Fullfilling ' + event.request.url + ' from cache');
      return pro;
    }).catch(function() {
      console.log('Loading ' + event.request.url);
      return fetch(event.request);
    })
  );
});

this.addEventListener('activate', function(event) {
  var cacheWhitelist = ['v1'];

  event.waitUntil(
    caches.keys().then(function(keyList) {
      return Promise.all(keyList.map(function(key) {
        if (cacheWhitelist.indexOf(key) === -1) {
          return caches.delete(keyList[i]);
        }
      }));
    })
  );
});