Skip to content

Skip browser cache writes for non-http(s) resources#1723

Open
patrickkettner wants to merge 1 commit into
huggingface:mainfrom
patrickkettner:browser-cache-scheme
Open

Skip browser cache writes for non-http(s) resources#1723
patrickkettner wants to merge 1 commit into
huggingface:mainfrom
patrickkettner:browser-cache-scheme

Conversation

@patrickkettner

Copy link
Copy Markdown

This replaces #614, the original report of this problem. That PR patched a file that has since been rewritten and moved, so it is being closed as obsolete in favor of this one. Related background: #380.

When a model is bundled inside a browser extension (env.localModelPath pointing at a chrome-extension:// URL) with the browser cache enabled, every file load attempts cache.put() with a chrome-extension:// key. The browser Cache API only supports http(s) request keys, so the put always fails: one call site logs Unable to add response to browser cache: TypeError: ... on every load, and the streaming path has no error handling at all.

This skips the write when the cache is the browser Cache API and the key is an absolute non-http(s) URL. Relative keys (e.g. the documented env.localModelPath = '/path/to/models/' pattern) are unaffected, since the Cache API resolves those against the page URL, and the other cache backends (FileCache, custom caches, Cross-Origin Storage) are untouched. One remaining gap worth knowing about: an extension page using a relative localModelPath still resolves to a chrome-extension:// request at put time; covering that would mean resolving keys against the page URL before the check, which seemed not worth the extra complexity here.

Tests cover the extension case (no put attempted), the relative-path case (still cached), and the remote case (still cached).

When a model is bundled inside a browser extension, cache.put() is
called with a chrome-extension:// key on every file load. The browser
Cache API only supports http(s) URLs as keys, so the put always fails:
one call site warns on every load and the other has no error handling
at all. Skip the write instead when the cache is the browser Cache API
and the key is an absolute non-http(s) URL. Relative keys still get
cached, since the Cache API resolves them against the page URL.
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