docs: add an Images guide covering img, svg and HTTP caching - #3239
Merged
Merged
Conversation
Add a "Cache remote images over HTTP" section to the Image page (en and zh-CN). It explains why GPUI's in-memory image cache does not avoid network requests, the rules for wrapping the application's HttpClient with an HTTP cache, and a compact in-memory example built on http-cache-semantics. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Add docs/image.md, covering img() sources, loading and decoding, sizing, svg(), choosing between them, decoded image caches with a custom ImageCache, and caching remote images over HTTP. Shorten the Image component page to common patterns that link to the guide. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Replace the hand-written cache with http-cache-reqwest middleware and a small adapter to GPUI's HttpClient. Build one client that follows redirects and one that does not, each with its own cache, so a caller that disables redirects still receives the 3xx. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add an Images guide under
docs/(website/docs/image.mdandwebsite/zh-CN/docs/image.md), and shorten the Image component page to the patterns applications use most, linking to the guide for details.The guide covers:
ImageSourceconversion loads its bytes (URL through the App'sHttpClient, asset key, file path,Arc<Image>,Arc<RenderImage>, custom loader), and that native apps must install anHttpClientbefore URL images load.with_loadingand animated images need an.id(...), what triggers the fallback, format detection from bytes, and SVG rasterization inimg().autodimensions andaspect_ratiocome from the decoded image, andObjectFit.svg():path,external_path,data; why it needs its own text color and an explicit size; paint-only transformations.img()orsvg(): a comparison table.image_cache(retain_all(...)), and a customImageCacheexample that keeps the most recently drawn images.HttpClientin a client that follows HTTP caching rules (Cache-Control,ETag/Last-Modifiedrevalidation, shared-cache restrictions, redirect policy in the cache key, size bounds, authorization before the request), with an example that adapts http-cache-reqwest middleware (disk store) to GPUI'sHttpClient. It builds one client that follows redirects and one that does not, each with its own cache, so a caller that requestsRedirectPolicy::NoFollowstill receives the3xx. The approach follows a production GPUI application that installs a global caching client.docs/assets.mdnow links to the guide. English and Chinese pages are kept in sync.No public API changes.
How to Test
ImageCacheandsvg()examples compile against this branch'sgpui-kit; the HTTP cache example was compiled and run against a local server: a repeated request is answered from the cache,NoFollowreceives the302, and a following request reaches the final200.typos,astro build, andbun test tests/seo.test.tspass; heading anchors used by cross-page links resolve.🤖 Generated with Claude Code