Skip to content

fix(pwa): cache ML model weights so they don't re-download on refresh - #86

Merged
slaveofcode merged 1 commit into
developfrom
fix/cache-ml-models
Aug 1, 2026
Merged

fix(pwa): cache ML model weights so they don't re-download on refresh#86
slaveofcode merged 1 commit into
developfrom
fix/cache-ml-models

Conversation

@slaveofcode

Copy link
Copy Markdown
Owner

The Whisper model re-downloaded on every refresh — transformers.js fetches it from huggingface.co (cross-origin) and its own Cache Storage wasn't persisting. Add a service-worker CacheFirst runtimeCaching rule for the HF hosts (incl. cdn-lfs*/*.hf.co redirect CDNs) + cdn.jsdelivr.net (ORT wasm), so our SW serves them from cache across refreshes.

Verified the rule is in the generated sw.js. build green.

⚠️ Caveat: if HF redirects the large-file bytes to a CDN host outside *.huggingface.co/*.hf.co (e.g. CloudFront), that host won't match — the fully-robust fallback is self-hosting the models on our R2. Will confirm with the reporter.

🤖 Generated with Claude Code

transformers.js fetches Whisper weights from huggingface.co (cross-origin) and
its own Cache Storage wasn't reliably persisting for users, so the model
re-downloaded on every refresh. Add a service-worker CacheFirst runtimeCaching
rule for the HF hosts (incl. cdn-lfs* / *.hf.co redirect CDNs) and cdn.jsdelivr
(ORT wasm) — our SW now serves them from cache across refreshes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
goodwebtools 680d6f4 Aug 01 2026, 11:51 AM

@slaveofcode
slaveofcode merged commit 4914b50 into develop Aug 1, 2026
2 checks passed
@slaveofcode
slaveofcode deleted the fix/cache-ml-models branch August 1, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant