Assets
MATLAB’s uihtml component serves the frontend through a local HTTPS server (https://127.0.0.1:{port}) that loads inside a CEF figure iframe. The underlying browser treats this server as a unique origin, which means it cannot fetch local files from disk or make cross-origin HTTP requests. An <img src="./photo.png"> in the HTML will fail because the browser has no access to MATLAB’s filesystem. Similarly, an <img src="https://example.com/logo.png"> will be blocked by CORS.
This is why assets must be sent from MATLAB as data: MATLAB reads the file or URL bytes, base64-encodes them, and pushes them across the bridge as strings. The ic.Asset class handles this transparently. It auto-detects the source type (local file, or URL), serializes the contents, and deduplicates repeated references so the same file is only sent once per View.
Serialization
When a property containing an ic.Asset is serialized for the bridge, the asset’s toStruct() method determines what gets sent:
- Lucide icon names are sent as plain strings. The frontend looks them up in its bundled icon map, which is loaded when the svelte component that requires them is dynamically imported.
- Files and URLs are read into bytes, hashed, base64-encoded, and sent as
{hash, mime, data}. - Empty assets are sent as
null.
The hash is a checksum computed from the raw bytes in pure MATLAB (no Java dependency) with low collision chance. The MIME type is derived from the file extension.
Deduplication
The same icon or image is often used by many components. Sending the full base64 payload every time would waste bandwidth. The ic.AssetRegistry tracks which hashes have already been sent to each View.
The first time an asset is serialized for a given View, AssetRegistry.hasSent(hash) returns false. The full payload is sent: {hash, mime, data}. The registry then calls markSent(hash) to record it.
Any later reference to the same file (same hash) skips the base64 data entirely. Only {hash} is sent. The JS side resolves it from its in-memory cache.
The registry tracks hashes per View, since each view is its own iframe context. When a View is destroyed, its hash map is cleaned up automatically. URL downloads, on the other hand, are cached globally: if two views reference the same URL, MATLAB only downloads it once.