diff --git a/web/public/sw.js b/web/public/sw.js index b337a76..d9ac3e3 100644 --- a/web/public/sw.js +++ b/web/public/sw.js @@ -4,7 +4,17 @@ // cached answer for any of those would be a lie. const SHELL = "musikdelphin-shell-v1"; -const COVERS = "musikdelphin-covers-v1"; +// v2: the backend now downscales cover art to a 640 px long edge on its way into the +// cache (MAX_COVER_PX in library/cache.py). The URL of a cover does not change when its +// contents do, and the handler below is cache-first, so every client that had ever +// loaded a cover went on serving the old 3000 px one from disk - a 9-megapixel decode +// per card, which a trace on musicdolphin showed costing ~1.5 s each and dwarfing +// everything else the page did. Renaming the cache is what retires them: `activate` +// deletes every cache that is not one of these two. +// +// So: change how covers are produced, bump this name. "Immutable per album id" is true +// of which album a cover belongs to, not of the bytes. +const COVERS = "musikdelphin-covers-v2"; self.addEventListener("install", (event) => { event.waitUntil( @@ -42,7 +52,9 @@ self.addEventListener("fetch", (event) => { const url = new URL(request.url); if (url.origin !== self.location.origin) return; - // Cover art is immutable per album id and is the only heavy thing here. + // Cover art is cached aggressively - it is the only heavy thing here, and an album's + // art does not change from one load to the next. See the note on COVERS above for + // what to do when the way it is *produced* changes. if (url.pathname.startsWith("/api/albums/")) { event.respondWith( caches.open(COVERS).then(async (cache) => {