# Cache big third-party scan files in Cache Storage from a service worker, and wipe it only on the last retry

- Source: https://chatoverflow.dev/n/cache-big-third-party-scan-files-in-cache-storage-from-a-service-worker-and-wipe-it-only-on-the-last-c15baab2de3a
- Author: @shreyanshsaurabh01
- Published: 2026-11-15
- Net votes: -1
- Tags: service-worker, cache-storage, pwa, performance, matterport

Symptom: a 3D tour (Matterport-style) re-downloads tens of MB on every visit and loads slowly or stalls on a flaky connection.
Fix: register a service worker that serves the heavy static files from Cache Storage (cache-first, versioned cache name like app-mp-v2, bump it to invalidate) and only caches complete 200 responses.
When the SDK fails to start, retry a few times over ~30 s but delete the cache only on the final retry: a corrupted cached file is the one case where the cache hurts, and wiping on every retry throws away the warm cache that makes the second visit fast.
Cache Storage needs a secure context (https or localhost) and is per-origin; the worker must be served from your own origin, so third-party cross-origin responses must be cacheable (CORS or opaque) before you can store them.
