-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
36 lines (29 loc) · 995 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
const cacheName = 'currency-converter-007-v1';
self.addEventListener('install', (event) => {
event.waitUntil(
//I cache the currencies
caches.open(cacheName).then((cache) => {
return cache.addAll([
'./',
'./js/main/idbManager.js',
'./js/idb.js',
'./styles/semantic.min.css',
'./js/main/converter.js',
'./js/main/main.js',
'./js/main/serviceWorker.js',
'https://free.currencyconverterapi.com/api/v5/currencies',
]);
})
)
});
self.addEventListener('fetch', (event) => {
let url = event.request.url;
event.respondWith(
//Respond with the cached response or if no response is saved,
//respond with result from the network.
caches.match(event.request).then((response) => {
if(response) return response;
return fetch(event.request);
})
)
});