This commit is contained in:
ntr 2019-04-08 13:55:23 +10:00
parent 29622d3c0c
commit 2f8ff69aee
2 changed files with 22 additions and 0 deletions

View File

@ -17,5 +17,14 @@
</head>
<body>
</body>
<script>
// Check that service workers are registered
if ('serviceWorker' in navigator) {
// Use the window load event to keep the page load performant
window.addEventListener('load', () => {
navigator.serviceWorker.register('./service.worker.js');
});
}
</script>
<script src="./index.js"></script>
</html>

13
client/service.worker.js Normal file
View File

@ -0,0 +1,13 @@
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request)
.then(function(response) {
// Cache hit - return response
if (response) {
return response;
}
return fetch(event.request);
}
)
);
});