prefetch
ts
function prefetch(
url: string,
options?: {
signal?: AbortSignal;
priority?: RequestPriority;
},
): void;Prefetch and cache data from a URL. A later call to imf.loadFileFromUrl() with the same URL will use the cached bytes or take ownership of the fetch if still in flight.
The data is removed from cache when consumed by loadFileFromUrl, or when discarded via the signal or clearPrefetch.
Parameters
| Parameter | Type | Description |
|---|---|---|
url | string | - |
options? | { signal?: AbortSignal; priority?: RequestPriority; } | - |
options.signal? | AbortSignal | Aborts the fetch and discards any bytes already downloaded. |
options.priority? | RequestPriority | Fetch priority hint. Use 'low' for background prefetching. |
Returns
void
Example
ts
import { prefetch } from '@imfusion/sdk';
const ac = new AbortController();
prefetch('/scans/ct.nii.gz', { signal: ac.signal });
// user navigates away before opening:
ac.abort();
// or user opens the file:
const data = await imf.loadFileFromUrl('/scans/ct.nii.gz'); // hits the cached prefetch