Agressively cache favicons fetched via icons.duckduckgo.com; Fall back to regular icon if image can't be loaded at all

This commit is contained in:
Martin Kleinschrodt 2021-12-08 14:33:19 +01:00
parent 0d8a6fc7aa
commit 7b1e7c68ad
2 changed files with 13 additions and 1 deletions

View File

@ -91,7 +91,9 @@ export class ItemIcon extends LitElement {
render() {
return html`
${this._favIcon ? html` <img .src=${this._favIcon} /> ` : html` <pl-icon .icon=${this._icon}></pl-icon> `}
${this._favIcon
? html` <img .src=${this._favIcon} @error=${() => (this._favIcon = undefined)} /> `
: html` <pl-icon .icon=${this._icon}></pl-icon> `}
`;
}
}

View File

@ -2,9 +2,19 @@
declare var self: ServiceWorkerGlobalScope;
import { precacheAndRoute } from "workbox-precaching";
import { registerRoute } from "workbox-routing";
import { CacheFirst } from "workbox-strategies";
precacheAndRoute(self.__WB_MANIFEST);
// Aggressively cache favicons fetched via icons.duckduckgo.com
registerRoute(
({ request }) => request.url.startsWith("https://icons.duckduckgo.com"),
new CacheFirst({
cacheName: "image-cache",
})
);
self.addEventListener("message", (event) => {
const action = event.data && event.data.type;