WebAssembly (Wasm) is a technology that ships in all modern browsers that lets developers ship portable binary programs.
This means that developers can use almost any programming language and target the web.
In the context of Discourse this opens up the door to shipping a fairly rich set of extensions that were only available to plugin creators in the past.
Examples could be:
- Image watermarking / resizing / cropping
- Graph generation using graphviz or svgbob
- Programming sandboxes (eg: a posts that embed a Ruby runtime)
- and much more
In the past due to the Discourse Content Security Policy access to Wasm was shut down except for installations with both local uploads and no CDN.
New interfaces were added to client side to support shipping JavaScript assets in a theme that are unconditionally reachable via local domain.
This enables theme developers to cleanly host Wasm, the flow is:
component → local web worker → Wasm hosted on CDN
Discourse svgbob is an end-to-end example of the new patterns, the 2 key changes are:
- All
.js
assets are also made available off CDN on local server:
{
...
"assets": {
"worker": "assets/will-be-avilable-on-local.js"
}
}
- The URL for the local asset is accessible via
settings.theme_uploads_local
So in the example above:
settings.theme_uploads_local.worker; // local asset
settings.theme_uploads.worker; // cdn asset