forked from elixirschool/elixirschool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserviceworker.js
More file actions
32 lines (28 loc) · 799 Bytes
/
serviceworker.js
File metadata and controls
32 lines (28 loc) · 799 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
28
29
30
31
32
---
layout: none
---
const preCachedResources = [
'/',
'{{ site.default_lang }}/',
'{% asset main.css @path %}',
'{% asset main.js @path %}'
];
const CACHE_NAME = '{{ site.name | slugify }}-v1';
self.addEventListener('install', event => {
event.waitUntil(caches.open(CACHE_NAME)
.then(cache => cache.addAll(preCachedResources))
.catch(error => console.log('Service worker installation has failed', error)));
});
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.open(CACHE_NAME)
.then(cache => {
return cache.match(event.request).then(response => {
return response || fetch(event.request).then(response => {
cache.put(event.request, response.clone());
return response;
});
});
})
);
});