mirror of
https://github.com/home-assistant/frontend.git
synced 2025-06-09 03:36:34 +00:00
Cache favicon too
This commit is contained in:
parent
26cf82fe8a
commit
2bc0f827b2
@ -3,6 +3,9 @@ const CACHE = '0.10';
|
|||||||
const INDEX_CACHE_URL = '/';
|
const INDEX_CACHE_URL = '/';
|
||||||
const INDEX_ROUTES = ['/', '/logbook', '/history', '/map', '/devService', '/devState',
|
const INDEX_ROUTES = ['/', '/logbook', '/history', '/map', '/devService', '/devState',
|
||||||
'/devEvent', '/devInfo', '/states'];
|
'/devEvent', '/devInfo', '/states'];
|
||||||
|
const CACHE_URLS = [
|
||||||
|
'/static/favicon-192x192.png',
|
||||||
|
];
|
||||||
|
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
console.log('Service Worker initialized.');
|
console.log('Service Worker initialized.');
|
||||||
@ -14,7 +17,7 @@ self.addEventListener('install', event => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
event.waitUntil(
|
event.waitUntil(
|
||||||
caches.open(CACHE).then(cache => cache.add(INDEX_CACHE_URL))
|
caches.open(CACHE).then(cache => cache.addAll(CACHE_URLS.concat(INDEX_CACHE_URL)))
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -35,7 +38,15 @@ self.addEventListener('message', event => {
|
|||||||
self.addEventListener('fetch', event => {
|
self.addEventListener('fetch', event => {
|
||||||
const path = event.request.url.substr(event.request.url.indexOf('/', 7));
|
const path = event.request.url.substr(event.request.url.indexOf('/', 7));
|
||||||
|
|
||||||
if (event.request.mode !== 'same-origin' || !INDEX_ROUTES.includes(path)) {
|
// TODO: do not cache requests to 3rd party hosts (or remove those calls)
|
||||||
|
|
||||||
|
if (CACHE_URLS.includes(path)) {
|
||||||
|
event.respondWith(
|
||||||
|
caches.open(CACHE).then(cache => cache.match(event.request))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!INDEX_ROUTES.includes(path)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,10 +58,6 @@ self.addEventListener('fetch', event => {
|
|||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (__DEV__ && cachedResponse) {
|
|
||||||
console.log('Serving cached response for', path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return cachedResponse || networkFetch;
|
return cachedResponse || networkFetch;
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user