Image Loading
Learn how image loading works in the Takumi pre-built HTTP server
When using takumi-server
, the src
property of an image node can be:
- A data URI (e.g.
data:image/png;base64,...
) - A file path (relative or absolute path on the server)
- A URL (e.g.
https://...
)
Image loading and caching in takumi-server
is handled by two main components:
-
Persistent Cache (
PersistentImageStore
):- Used for images that are preloaded or explicitly inserted into the cache (e.g. via API or initialization).
- Fast, in-memory, and does not support fetching from remote sources.
- If an image is found in the persistent cache, it is used immediately.
-
Remote Cache (
HttpImageStore
):- Used for images loaded from URLs (e.g. HTTP/HTTPS links).
- Maintains an LRU cache of recently fetched images.
Image Loading Order
When rendering an image node, Takumi resolves the src
in the following order:
- Data URI: If the
src
is a data URI, it is decoded and loaded directly (requires theimage_data_uri
feature). - Persistent Cache: If the image is present in the persistent cache, it is used.
- Remote Cache: If the image is not in the persistent cache and the
src
is a URL, the remote cache is checked. If not present, it is fetched and cached (requires thehttp_image_store
feature).