forked from udacity/mws-restaurant-stage-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
61 lines (57 loc) · 1.64 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
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open('restaurant').then((cache) => {
return cache.addAll([
'/',
'/index.html',
'/restaurant.html',
'/css/styles.css',
'/js/main.js',
'/js/restaurant_info.js',
'/js/dbhelper.js',
'/data/restaurants.json',
'/images/',
'/images/1-400small.jpg',
'/images/1-600medium.jpg',
'/images/2-400small.jpg',
'/images/2-600medium.jpg',
'/images/3-400small.jpg',
'/images/3-600medium.jpg',
'/images/4-400small.jpg',
'/images/4-600medium.jpg',
'/images/5-400small.jpg',
'/images/5-600medium.jpg',
'/images/6-400small.jpg',
'/images/6-600medium.jpg',
'/images/7-400small.jpg',
'/images/7-600medium.jpg',
'/images/8-400small.jpg',
'/images/8-600medium.jpg',
'/images/9-400small.jpg',
'/images/9-600medium.jpg',
'/images/10-400small.jpg',
'/images/10-600medium.jpg'
]).then(() => {
console.log('All Files are cached');
return self.skipWaiting();
}).catch((error) => {
console.log('Failed to cache', error);
})
})
);
});
self.addEventListener('activate', (event) => {
console.log('Service worker activating...');
});
self.addEventListener('fetch', (event) => {
event.respondWith(
caches.open('restaurant').then((cache) => {
return cache.match(event.request).then((response) => {
return response || fetch(event.request).then((response) => {
cache.put(event.request, response.clone());
return response;
});
});
})
);
});