-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
42 lines (35 loc) · 982 Bytes
/
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
// Polyfill for Chrome caching
importScripts('js/cache-polyfill.js');
// Install the ServiceWorker
self.addEventListener('install', function(event) {
event.waitUntil(
// Open a cache
caches.open('v1').then(function(cache) {
// Define what we want to cache
return cache.addAll([
'/',
'index.html',
'js/app.js',
'js/jquery.min.js',
'js/note-list.js',
'css/style.css',
'favicon.ico',
'manifest.json',
'img/icon-60.png',
'img/icon-114.png',
'img/icon-152.png'
]);
})
);
});
// Use ServiceWorker (or not) to fetch data
self.addEventListener('fetch', function(event) {
event.respondWith(
// Look for something in the cache that matches the request
caches.match(event.request).then(function(response) {
// If we find something, return it
// Otherwise, use the network instead
return response || fetch(event.request);
})
);
});