Merge pull request #5 from AverageMarcus/service_worker
Added service worker
This commit is contained in:
commit
09e95c1b65
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -34,4 +34,11 @@
|
|||||||
|
|
||||||
<link rel="stylesheet" href="/css/main.css?{{moment date 'YYYYMMDDHHMM'}}">
|
<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">
|
<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>
|
</head>
|
||||||
|
Loading…
Reference in New Issue
Block a user