sw
This commit is contained in:
@@ -17,5 +17,14 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
</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>
|
<script src="./index.js"></script>
|
||||||
</html>
|
</html>
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user