https://unpkg.com/@rive-app/canvas@x.x.x/rive.wasm which retrieves a Web Assembly (WASM) file that contains Rive-specific APIs to build the render loop. unkpg is a global CDN that quickly allows for loading in NPM packages, which in this case includes a WASM file. This allows for a smaller bundle size when pulling in the Rive JS-based runtimes, while only loading in WASM when Rive instances are created.
Self-hosting Rive WASM
Whileunpkg should provide WASM quickly, you may want to preload and host the WASM file yourself as a static same-origin asset for any of the following reasons:
- Strict control over the origin of the WASM powering the Rive animations, as opposed to relying on a third-party unpkg CDN
- Faster load times for initializing Rive
- Ability to control caching policy of the
rive.wasmfile
Initializing Rive on page load
If you need Rive to be ready to render your graphics immediately on page load (i.e. hero animations), we recommend preloading both therive.wasm file and the .riv file so the browser begins downloading the necessary resources up front. On the JS side, you can use the RuntimeLoader API to begin downloading and compiling the WASM early, before the Rive component mounts.
By default, the React runtime fetches rive.wasm from unpkg at the @rive-app/canvas version it pins — you don’t need to call RuntimeLoader.setWasmUrl() for this. To preload it, just point a <link rel="preload"> at that same URL (see the version note above for finding the version):
@rive-app/canvas is only a transitive
dependency of the React runtime, this import resolves under npm/yarn (which hoist it) but fails under pnpm unless you add @rive-app/canvas to your own package.json at the matching version.