Skip to content

fix(voice-to-text): proxy HF model weights same-origin so they cache - #90

Merged
slaveofcode merged 1 commit into
developfrom
fix/hf-model-proxy
Aug 1, 2026
Merged

fix(voice-to-text): proxy HF model weights same-origin so they cache#90
slaveofcode merged 1 commit into
developfrom
fix/hf-model-proxy

Conversation

@slaveofcode

Copy link
Copy Markdown
Owner

Root cause of the re-download-every-refresh: transformers.js fetches Whisper weights from huggingface.co, which 302-redirects large files to a CDN — and neither the browser nor Workbox reliably caches redirected cross-origin responses.

Fix: a /hf/* proxy on the edge Worker resolves the redirect server-side and returns the bytes same-origin with immutable cache (+ CF edge cache). transformers.js env.remoteHost points at it (localhost dev skips it). The browser HTTP-caches the same-origin immutable response — the exact mechanism that already makes the OCR model cache reliably — so it survives refreshes. Degrades to the default host if env can't be set.

Worker bundle validated via wrangler --dry-run; build green. Will verify the live /hf/… endpoint with curl after deploy.

🤖 Generated with Claude Code

The Whisper model re-downloaded on every refresh: transformers.js fetches weights
from huggingface.co, which 302-redirects large files to a CDN, and neither the
browser nor Workbox reliably caches redirected cross-origin responses.

Add a /hf/* proxy to the edge Worker that resolves the redirect server-side and
returns the bytes same-origin with 'cache-control: immutable' (+ Cloudflare edge
cache). Point transformers.js env.remoteHost at it (skipped on localhost dev).
The browser HTTP-caches the same-origin immutable response — the same mechanism
that already makes the self-hosted OCR model cache reliably — so it survives
refreshes. Falls back to the default host if env can't be set.

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 9aecbb8 Aug 01 2026, 12:18 PM

@slaveofcode
slaveofcode merged commit f99c542 into develop Aug 1, 2026
2 checks passed
@slaveofcode
slaveofcode deleted the fix/hf-model-proxy branch August 1, 2026 12:18
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