diff --git a/public/sw.js b/public/sw.js index edc756a..6e8f608 100644 --- a/public/sw.js +++ b/public/sw.js @@ -59,7 +59,9 @@ async function cacheFirst(req) { const hit = await cache.match(req); if (hit) return hit; const res = await fetch(req); - if (res && res.ok) cache.put(req, res.clone()); + // Await the write: respondWith() keeps the worker alive for this promise, so the asset is + // actually persisted before the worker can be terminated (otherwise offline use loses it). + if (res && res.ok) await cache.put(req, res.clone()); return res; }