Skip to main content

JS vs WASM Runtime

Dim ships two runtimes with the same public API: a pure JS core and a Rust/WASM core. Apps switch with a URL flag or by loading a different global bundle.


Bundles​

FileRuntime
dim.global.jsPure JS (default)
dim.wasm.global.jsRust core, WASM inlined (base64)

CDN base: https://positive-intentions.github.io/dim/lib/

<!-- JS -->
<script src="https://positive-intentions.github.io/dim/lib/dim.global.js"></script>

<!-- WASM -->
<script src="https://positive-intentions.github.io/dim/lib/dim.wasm.global.js"></script>

dimui and dim-boilerplate use ?impl=js or ?impl=wasm and persist the choice. Both expose the same window.Dim API.


Framework tests (dim repo contributors)​

App authors use DimTest in the browser (Unit tests). Contributors working on Dim itself:

npm test           # Jest against JS
npm run test:wasm # same suites with DIM_IMPL=wasm
npm run test:rust # cargo tests
npm run test:all # JS + Rust + WASM

App DimTest suites (boilerplate / dimui) also run both impls in CI.


Caveats​

  • Size. WASM global builds embed the .wasm as base64 (~310 KB vs ~105 KB JS). Split builds are smaller but need top-level await and HTTP.
  • CSP. Instantiating WebAssembly needs script-src 'wasm-unsafe-eval' under a strict CSP.
  • Performance. Every DOM commit still crosses the JS↔WASM boundary; WASM is not faster than JS for typical UI work.
  • Behaviour. The WASM committer skips parts whose value is the identical primitive (or same listener) as last commit — a commit optimization, not a Lit dependency. External DOM edits to a bound text node may not revert until the value changes.