-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
60 lines (56 loc) · 1.49 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
let staticCacheName = 'static-cache-v1'; // Cache version
// Files to cache
const assets = [
'.',
'index.html',
'restaurant.html',
'./css/styles.css',
'./js/main.js',
'./js/dbhelper.js',
'./js/restaurant_info.js',
'./data/restaurants.json',
'./img/1.webp',
'./img/2.webp',
'./img/3.webp',
'./img/4.webp',
'./img/5.webp',
'./img/6.webp',
'./img/7.webp',
'./img/8.webp',
'./img/9.webp',
'./img/10.webp',
'./favicon.ico',
'./img/restaurant-app.png',
'https://fonts.googleapis.com/css?family=Playfair+Display:900i|Poppins',
];
//Install
self.addEventListener('install', function (e) {
e.waitUntil(
caches.open(staticCacheName).then((cache) => {
return cache.addAll(assets);
})
);
});
//Removes old cache
self.addEventListener('activate', function (event) {
event.waitUntil(
caches.keys().then(function (cacheNames) {
return Promise.all(
cacheNames.filter(function (cacheName) {
return cacheName.startsWith('static-') &&
cacheName != staticCacheName;
}).map(function (cacheName) {
return cache.delete(cacheName);
})
)
})
)
})
// Respond requests
self.addEventListener('fetch', (event) => {
event.respondWith(
caches.match(event.request).then((response) => {
return response || fetch(event.request)
})
);
});