Skip to content

probe-web / @probe-web/client / index / prefetchWasm

Function: prefetchWasm()

ts
function prefetchWasm(): void;

Defined in: index.ts:118

Start downloading the wasm the WebUSB transport needs, before anything asks for it.

Nothing requests the worker's module until Client.connect runs, so by default the whole download — about 2.8 MB compressed — lands inside the wait after the user has clicked connect. Calling this earlier moves it out of that wait.

It is a hint, not a load: the browser fetches at the lowest priority into its HTTP cache and nothing is instantiated or held in memory, so a visitor who never connects a probe pays only for the bytes. Compiling costs about 30 ms either way, which is why this warms the download rather than keeping a worker alive.

Call it when a probe is likely to be used — the origin has already been granted one, say, or the pointer is over the connect button — not on page load, which would spend a first-time visitor's bandwidth on a page they may only be reading.

Safe to call repeatedly; only the first call does anything. No-op outside a browser.

Returns

void

Example

ts
import { prefetchWasm } from '@probe-web/client';
import { grantedProbes } from '@probe-web/devices';

// This visitor has connected a probe here before, so they will probably do it again.
if ((await grantedProbes()).length) prefetchWasm();