Added service worker
This commit is contained in:
parent
21ba182d67
commit
628c620093
18
src/service-worker.js
Normal file
18
src/service-worker.js
Normal file
@ -0,0 +1,18 @@
|
||||
var CACHE = 'v1';
|
||||
|
||||
self.addEventListener('fetch', function(event) {
|
||||
event.respondWith(fetchAndCache(event));
|
||||
});
|
||||
|
||||
function fetchAndCache(event) {
|
||||
return caches.open(CACHE).then(function (cache) {
|
||||
return fetch(event.request)
|
||||
.then(function(response) {
|
||||
cache.put(event.request, response.clone());
|
||||
return response;
|
||||
})
|
||||
.catch(function() {
|
||||
return cache.match(event.request);
|
||||
});
|
||||
});
|
||||
}
|
@ -33,4 +33,11 @@
|
||||
|
||||
<link rel="stylesheet" href="/css/main.css?{{moment date 'YYYYMMDDHHMM'}}">
|
||||
<link rel="alternate" type="application/rss+xml" title="{{ site.title }}" href="{{ site.url }}/feed.xml">
|
||||
<script>
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', function() {
|
||||
navigator.serviceWorker.register('/service-worker.js', { scope: '/' });
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
Loading…
Reference in New Issue
Block a user