Skip to content

Inline Wasm into JavaScript source #10

@timfish

Description

@timfish

Currently the wasm is in a separate file and is loaded like this:

const path = require('path').join(__dirname, 'orchestrion_js_bg.wasm');
const bytes = require('fs').readFileSync(path);

const wasmModule = new WebAssembly.Module(bytes);
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);

This will not be compatible with some bundlers which may be an issue in some use cases.

We could run a post-build script that inlined the wasm as a base64 string like this:

const bytes = Buffer.from('2.6MB-data-in~3.5MB-base64-string==', 'base64');

const wasmModule = new WebAssembly.Module(bytes);
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);

Potential Issues

  • The uncompressed package will be 33% larger
  • Might impact startup performance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions