Commit d2d9d3a4 authored by Julien Enselme's avatar Julien Enselme

Display offline page when app is offline

parent b3b6e5d3
......@@ -47,7 +47,19 @@ self.addEventListener('fetch', (event) => {
return res;
})
})
.catch(err => console.warn('Warning: app is offline', err));;
.catch(err => {
console.warn('[SW] Network request failed, app is probably offline', err);
return caches.open(staticCacheName)
})
.then(cache => {
// If the request expects an HTML response, we display the offline page.
if (event.request.headers.get('accept').includes('text/html')) {
return cache.match('/offline/');
}
return Promise.reject()
})
.catch(err => console.warn('[SW] failed to get response from network and cache.', err));
}),
);
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment