git ssb

0+

Rômulo Alves / website



Tree: 20738f5c6c86f792bd1d29630749a0e32572a0b6

Files: 20738f5c6c86f792bd1d29630749a0e32572a0b6 / src / service-worker.js

991 bytesRaw
1var CACHE_NAME = '20161003';
2var urlsToCache = [
3 '/',
4 '/favicon.png'
5];
6
7self.addEventListener('install', function(event) {
8 event.waitUntil(
9 caches.open(CACHE_NAME)
10 .then(function(cache) {
11 return cache.addAll(urlsToCache);
12 })
13 );
14});
15
16self.addEventListener('fetch', function(event) {
17 event.respondWith(
18 caches.match(event.request)
19 .then(function(response) {
20 if (response) {
21 return response;
22 }
23
24 var fetchRequest = event.request.clone();
25 return fetch(fetchRequest).then(
26 function(response) {
27 if(!response || response.status !== 200 || response.type !== 'basic') {
28 return response;
29 }
30
31 var responseToCache = response.clone();
32 caches.open(CACHE_NAME)
33 .then(function(cache) {
34 cache.put(event.request, responseToCache);
35 });
36
37 return response;
38 }
39 );
40 })
41 );
42});
43

Built with git-ssb-web