-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsw.js
56 lines (53 loc) · 1.59 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
var FILE_VERSION = ''
var CACHE_NAME = 'whatsapp-direct' + FILE_VERSION
/* Start the service worker and cache all of the app's content */
self.addEventListener('install', function (e) {
var filesToCache = [
'index.html',
'assets/css/style.css',
'assets/scripts/sw-install.js',
'assets/scripts/index.js'
]
e.waitUntil(
caches
.open(CACHE_NAME)
.then(function (cache) {
return cache.addAll(
filesToCache.map(function (file) {
return file + FILE_VERSION
}).concat('https://cdn.rawgit.com/neocotic/qrious/master/dist/qrious.min.js')
)
})
.then(function () {
self.skipWaiting()
})
)
})
/* Serve cached content when offline */
self.addEventListener('fetch', function (e) {
e.respondWith(
caches.match(e.request).then(function (response) {
return response || fetch(e.request)
})
)
})
self.addEventListener('activate', function (e) {
e.waitUntil(
caches
.keys()
.then(function (keyList) {
return Promise.all(
keyList
.filter(function (key) {
return CACHE_NAME === key
})
.map(function (key) {
return caches.delete(key)
})
)
})
.then(function () {
self.clients.claim()
})
)
})