Skip to content

docs: add an Images guide covering img, svg and HTTP caching - #3239

Merged
huacnlee merged 3 commits into
mainfrom
docs/remote-image-http-cache
Sep 25, 2026
Merged

huacnlee merged 3 commits into
mainfrom
docs/remote-image-http-cache

Conversation

@huacnlee

@huacnlee huacnlee commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Description

Add an Images guide under docs/ (website/docs/image.md and website/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:

  • Sources: how each ImageSource conversion loads its bytes (URL through the App's HttpClient, asset key, file path, Arc<Image>, Arc<RenderImage>, custom loader), and that native apps must install an HttpClient before URL images load.
  • Loading, decoding, and failures: the 200 ms loading delay, why with_loading and animated images need an .id(...), what triggers the fallback, format detection from bytes, and SVG rasterization in img().
  • Size and fit: how auto dimensions and aspect_ratio come from the decoded image, and ObjectFit.
  • svg(): path, external_path, data; why it needs its own text color and an explicit size; paint-only transformations.
  • img() or svg(): a comparison table.
  • Caches for decoded images: the App asset cache, scoped caches with image_cache(retain_all(...)), and a custom ImageCache example that keeps the most recently drawn images.
  • Cache remote images over HTTP: wrap the App's HttpClient in a client that follows HTTP caching rules (Cache-Control, ETag/Last-Modified revalidation, 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's HttpClient. It builds one client that follows redirects and one that does not, each with its own cache, so a caller that requests RedirectPolicy::NoFollow still receives the 3xx. The approach follows a production GPUI application that installs a global caching client.
  • Troubleshooting.

docs/assets.md now links to the guide. English and Chinese pages are kept in sync.

No public API changes.

How to Test

  • The ImageCache and svg() examples compile against this branch's gpui-kit; the HTTP cache example was compiled and run against a local server: a repeated request is answered from the cache, NoFollow receives the 302, and a following request reaches the final 200.
  • typos, astro build, and bun test tests/seo.test.ts pass; heading anchors used by cross-page links resolve.

🤖 Generated with Claude Code

huacnlee and others added 2 commits September 25, 2026 23:21
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>
@huacnlee huacnlee changed the title docs: Explain HTTP caching for remote images docs: add an Images guide covering img, svg and HTTP caching Sep 25, 2026
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>
@huacnlee
huacnlee enabled auto-merge (squash) September 25, 2026 15:52
@huacnlee
huacnlee merged commit 1028a4e into main Sep 25, 2026
12 checks passed
@huacnlee
huacnlee deleted the docs/remote-image-http-cache branch September 25, 2026 15:55
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