# Loading the SDK

> npm, the CDN with an integrity hash, bundlers, TypeScript and Content-Security-Policy.

## From npm

```sh
npm install jsflow-sdk
```

The 0.0.x versions on npm are unrelated and deprecated. Vite and webpack bundle the SDK and its worker automatically. Anywhere else, serve `worker.js` (it is in the package, next to `jsflow.js`) and pass its URL: `join({ worker: '/assets/worker.js' })`.

## From the CDN

`https://cdn.jsflow.com/v1.1.3/jsflow.js`: plain ES modules, no dependencies, with CORS for any origin. A version directory holds two files, `jsflow.js` and `worker.js`, and the worker must stay next to the SDK (the SDK finds it there). **A published version never changes**, so pin it and keep the URL in one constant. New versions are listed in the [changelog](https://jsflow.com/docs/reference/changelog.md).

### Integrity (SRI)

Each version directory has `sri.json` with the SHA-384 hash of its files. An import map can make the browser refuse a file that differs:

```html title="index.html"
<script type="importmap">
{
  "imports": {
    "jsflow-sdk": "https://cdn.jsflow.com/v1.1.3/jsflow.js"
  },
  "integrity": {
    "https://cdn.jsflow.com/v1.1.3/jsflow.js":
      "sha384-sQqHAdflDDfP6VfM2G8YqC1hhovmh2U2eb+iNhq+HXfoNI4x/2SlOlIHl7T4mfwH"
  }
}
</script>
<script type="module">
  import { join, text } from 'jsflow-sdk';
</script>
```

Take the hash from the `sri.json` of the version you pin; it changes with every version. A browser that does not support integrity in import maps ignores the key and loads the file as usual, so the pin is still your protection there.

## Bundlers

Vite, webpack and Next bundle the worker for you; [Bundlers and CSP](https://jsflow.com/docs/guides/bundlers-and-csp.md) has the esbuild setup and what a Content-Security-Policy needs. With npm, import the package as usual. To use the CDN copy from a bundled app, import it at runtime so the bundler leaves it alone:

```ts
const SDK = 'https://cdn.jsflow.com/v1.1.3/jsflow.js';
// Vite
const jsflow = await import(/* @vite-ignore */ SDK);
// webpack
const jsflow2 = await import(/* webpackIgnore: true */ SDK);
void jsflow; void jsflow2;
```

## TypeScript

The npm package carries its types. For the CDN, download `jsflow.d.ts` from the same version's folder (`https://cdn.jsflow.com/v1.1.3/jsflow.d.ts`) into your source tree, then:

```ts
const jsflow: typeof import('./jsflow') =
  await import(/* @vite-ignore */ SDK);
const room: import('./jsflow').Room =
  await jsflow.join({ app, room: name });
```

## Content-Security-Policy

If your page sends a Content-Security-Policy, it has to allow the SDK's script, its worker and the signalling service: [Bundlers and CSP](https://jsflow.com/docs/guides/bundlers-and-csp.md#content-security-policy) lists the three directives and why each is needed.

## Browsers

The SDK needs Web Crypto X25519 and Ed25519: Chrome and Edge 137, Safari 17 and Firefox 130 or newer. An older browser gets `unsupported_browser` from `join()` before any request is made.

## Licence

jsflow-sdk 1.0 comes with the jsflow SDK and CLI licence (the `LICENSE` file in the package and beside the build): free to use with the jsflow service, in development, testing and production, to bundle and ship in your apps, and to let your end users run, with no account for them. Each 0.1 build comes with a dated permission, published beside it: [`https://cdn.jsflow.com/v0.1.3/PERMISSION-2026-11-18.txt`](https://cdn.jsflow.com/v0.1.3/PERMISSION-2026-11-18.txt).

Source: https://jsflow.com/docs/guides/loading-the-sdk/
