Passed
Pull Request — develop (#256)
by Xaver
01:38
created

service-worker.js   A

Complexity

Total Complexity 7
Complexity/F 1.17

Size

Lines of Code 23
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 7
c 1
b 0
f 0
nc 1
mnd 1
bc 7
fnc 6
dl 0
loc 23
rs 10
bpm 1.1666
cpm 1.1666
noi 5
1
self.addEventListener('install', function (event) {
2
  var offlineRequest = new Request('offline.html');
3
  event.waitUntil(
4
    fetch(offlineRequest).then(function (response) {
5
      return caches.open('offline').then(function (cache) {
6
        return cache.put(offlineRequest, response);
7
      });
8
    })
9
  );
10
});
11
12
self.addEventListener('fetch', function (event) {
13
  var request = event.request;
14
  if (request.method === 'GET') {
15
    event.respondWith(
16
      fetch(request).catch(function () {
17
        return caches.open('offline').then(function (cache) {
18
          return cache.match('offline.html');
19
        });
20
      })
21
    );
22
  }
23
});
24