fix and update service worker

This commit is contained in:
Rich Harris
2018-03-03 21:41:26 -05:00
parent dad66403ce
commit ec1db3fc34
2 changed files with 7 additions and 4 deletions

View File

@@ -37,8 +37,11 @@ self.addEventListener('fetch', event => {
// don't try to handle e.g. data: URIs
if (!url.protocol.startsWith('http')) return;
// ignore dev server requests
if (url.hostname === self.location.hostname && url.port !== self.location.port) return;
// always serve assets and webpack-generated files from cache
if (cached.has(url.pathname)) {
if (url.host === self.location.host && cached.has(url.pathname)) {
event.respondWith(caches.match(event.request));
return;
}

View File

@@ -10,9 +10,9 @@
<link rel='icon' type='image/png' href='/favicon.png'>
<script>
// if ('serviceWorker' in navigator) {
// navigator.serviceWorker.register('/service-worker.js');
// }
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js');
}
</script>
<!-- Sapper generates a <style> tag containing critical CSS