-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsw.js
More file actions
27 lines (25 loc) · 707 Bytes
/
sw.js
File metadata and controls
27 lines (25 loc) · 707 Bytes
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
/* eslint-disable max-nested-callbacks */
const cacheName = 'www.runpkg.com';
self.addEventListener('activate', () => {
console.log('service worker activated');
});
self.addEventListener('fetch', event => {
if (
event.request.url.includes('https://unpkg') &&
!event.request.referrer.includes('https://unpkg.com/')
) {
event.respondWith(
caches.open(cacheName).then(cache =>
cache.match(event.request).then(
response =>
response ||
fetch(event.request).then(networkResponse => {
cache.put(event.request, networkResponse.clone());
return networkResponse;
})
)
)
);
}
return;
});