-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathworker.js
More file actions
86 lines (73 loc) · 2.41 KB
/
worker.js
File metadata and controls
86 lines (73 loc) · 2.41 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var CACHE_NAME = 'inkstone-v1.1.10';
var BASE_DIR = '/inkstone';
// The files we want to cache
var urlsToCache = [
BASE_DIR + '/',
BASE_DIR + '/manifest.json',
BASE_DIR + '/img/png/inkstone144.png',
BASE_DIR + '/img/png/inkstone192.png',
BASE_DIR + '/img/svg/inkstone.svg',
BASE_DIR + '/img/svg/inkling.svg',
BASE_DIR + '/scripts/app-bundle.js',
BASE_DIR + '/scripts/app-bundle.js.map',
BASE_DIR + '/scripts/require.js',
BASE_DIR + '/scripts/text.js',
BASE_DIR + '/scripts/vendor-bundle.js',
BASE_DIR + '/img/icons/circle-icons/audio.svg',
BASE_DIR + '/img/icons/circle-icons/bookmark.svg',
BASE_DIR + '/img/icons/circle-icons/bubble.svg',
BASE_DIR + '/img/icons/circle-icons/calendar.svg',
BASE_DIR + '/img/icons/circle-icons/check.svg',
BASE_DIR + '/img/icons/circle-icons/document.svg',
BASE_DIR + '/img/icons/circle-icons/film.svg',
BASE_DIR + '/img/icons/circle-icons/heart.svg',
BASE_DIR + '/img/icons/circle-icons/lens.svg',
BASE_DIR + '/img/icons/circle-icons/location.svg',
BASE_DIR + '/img/icons/circle-icons/memcard.svg',
BASE_DIR + '/img/icons/circle-icons/mic.svg',
BASE_DIR + '/img/icons/circle-icons/pencil.svg',
BASE_DIR + '/img/icons/circle-icons/person.svg',
BASE_DIR + '/img/icons/circle-icons/photo.svg',
BASE_DIR + '/img/icons/circle-icons/power.svg',
BASE_DIR + '/img/icons/circle-icons/recycle.svg',
BASE_DIR + '/img/icons/circle-icons/search.svg',
BASE_DIR + '/img/icons/circle-icons/settings.svg',
BASE_DIR + '/img/icons/circle-icons/uparrow.svg'
];
// Set the callback for the install step
self.addEventListener('install', function(event) {
// Perform install steps
event.waitUntil(
caches.open(CACHE_NAME)
.then(function(cache) {
console.log('Opened cache');
return cache.addAll(urlsToCache);
})
);
});
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request)
.then(function(response) {
// Cache hit - return response
if (response) {
return response;
}
return fetch(event.request);
}
)
);
});
self.addEventListener('activate', function(event) {
event.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.map(function(cacheName) {
if(cacheName !== CACHE_NAME) {
return caches.delete(cacheName);
}
})
);
})
);
});