# Use in the browser

Load one artifact, resolve remote sidecars asynchronously, and move CPU work to a worker.

Canonical page: https://libassimp.xyz/docs/guides/use-in-the-browser

## Convert picked bytes [#convert-picked-bytes]

```typescript
import { convert } from 'libassimp';

const toGlb = async (file: File): Promise<Uint8Array> => {
  const bytes = new Uint8Array(await file.arrayBuffer());
  const { files } = await convert({ name: file.name, bytes }, { to: 'glb' });
  return files[0].bytes;
};
```

## One artifact, automatic async route [#one-artifact-automatic-async-route]

Each package entry ships one Wasm artifact. During instantiation, libassimp checks for both `WebAssembly.Suspending` and `WebAssembly.promising`. A capable host uses JSPI to suspend Assimp parsing around an async resolver; every other supported host uses promise-cache replay. There is no user-agent test, alternate URL, or public mode option.

```typescript
import { createAssimp } from 'libassimp';

using assimp = await createAssimp({
  wasmUrl: new URL('/assets/libassimp.wasm', location.href),
});

const bytes = new Uint8Array();
const { files } = await assimp.convert(
  { name: 'scene.gltf', bytes },
  {
    to: 'glb',
    resolve: async (name) => {
      const response = await fetch(`/models/${name}`);
      return response.ok ? new Uint8Array(await response.arrayBuffer()) : undefined;
    },
  },
);

console.log(files[0].name);
```

Serve Wasm with `application/wasm`, content-hashed immutable caching, and compression. Streaming compilation falls back to buffered compilation when MIME or host behavior requires it.

## Use a worker [#use-a-worker]

A conversion is CPU-heavy even when resolution suspends. Import libassimp inside a module worker and transfer input/output buffers. The artifact has no pthreads, so no cross-origin isolation headers are required.

```typescript
const worker = new Worker(new URL('./convert-worker.js', import.meta.url), { type: 'module' });
worker.postMessage({ name: 'model.fbx', bytes: new Uint8Array() });
```

## Download output [#download-output]

```typescript
const download = (name: string, bytes: Uint8Array<ArrayBuffer>): void => {
  const url = URL.createObjectURL(new Blob([bytes]));
  const anchor = Object.assign(document.createElement('a'), { download: name, href: url });
  anchor.click();
  URL.revokeObjectURL(url);
};
```

The canonical [compatibility matrix](https://github.com/taucad/libassimp/blob/main/compatibility.md) records browser floors and which current hosts accelerate through JSPI.