mesh
mesh copied to clipboard
Load WASM libraries asynchronously
Should the wasm libraries like https://github.com/MeshJS/mesh/blob/main/packages/module/src/core/CSL.ts#L3 not be loaded asynchronously ideally with await import
? Since I added Mesh to a Next.js project the build time and first load times increased dramatically. I had this same problem when I was directly using the Emurgo WASM packages in another project, I instead had to create a Loader class which lazy loads the libraries on demand at first use, and that significantly improved the app's build and initial response times
The loader class just looked like this:
class WasmLoader {
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
private csl: typeof import('@emurgo/cardano-serialization-lib-browser') | undefined;
async load() {
if (this.csl) {
return;
}
this.csl = await import('@emurgo/cardano-serialization-lib-browser');
}
get CSL() {
return this.csl;
}
}
export const loader = new WasmLoader();
We will not further investigate workaround on this, as we hope to solve all these wasm related issues with pure JS dependency - https://github.com/MeshJS/mesh/tree/main/packages/mesh-core-cst.