-
Notifications
You must be signed in to change notification settings - Fork 1
/
sw.js
64 lines (57 loc) · 1.88 KB
/
sw.js
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
55
56
57
58
59
60
61
62
63
64
'use strict';
var CACHE_NAME = 'offline-issues-cache-v2';
var PLACEHOLDER_SVG = "<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 {{w}} {{h}}'><defs><symbol id='a' viewBox='0 0 90 66' opacity='0.3'><path d='M85 5v56H5V5h80m5-5H0v66h90V0z'/><circle cx='18' cy='20' r='6'/><path d='M56 14L3739l-8-6-17 23h67z'/></symbol></defs><use xlink:href='#a' width='20%' x='40%'/></svg>";
var urlsToCache = [
'./',
'css/bootstrap.css',
'css/app.css',
'js/lodash.js',
'js/jquery-2.2.4.js',
'js/bootstrap.js',
'js/github.bundle.min.js',
'js/pouchdb-5.4.5.js',
'js/pouchdb.all-dbs.js',
'js/moment.min.js',
'js/marked.js',
'js/commentWorker.js',
'js/app.js'
];
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(CACHE_NAME)
.then(function(cache) {
console.log('Opened cache');
return cache.addAll(urlsToCache);
})
);
});
self.addEventListener('activate', function(event) {
event.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.filter(function(cacheName) {
return cacheName !== CACHE_NAME;
}).map(function(cacheName) {
return caches.delete(cacheName);
})
);
})
);
});
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.open(CACHE_NAME).then(function(cache) {
return fetch(event.request)
.then(function(response) {
cache.put(event.request, response.clone());
return response;
})
.catch(function(err) {
var acceptHeader = event.request.headers.get('Accept');
if (acceptHeader.startsWith('image')) {
return new Response(PLACEHOLDER_SVG, { headers: { 'Content-Type': 'image/svg+xml' }});
}
});
})
);
});