Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jayphelps/wasmjs-binary-bundles
Experimenting with combining WebAssembly and JavaScript into a single file bundle
https://github.com/jayphelps/wasmjs-binary-bundles
Last synced: 16 days ago
JSON representation
Experimenting with combining WebAssembly and JavaScript into a single file bundle
- Host: GitHub
- URL: https://github.com/jayphelps/wasmjs-binary-bundles
- Owner: jayphelps
- License: mit
- Created: 2018-07-19T02:45:04.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-14T19:32:21.000Z (about 6 years ago)
- Last Synced: 2024-12-17T21:44:17.996Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wasmjs-binary-bundles
Proof of concept experiment combining WebAssembly and JavaScript into a single file with the idea that maybe any JS runtime required wouldn't need a separate network request. This sort of makes a "bundle" of both Wasm and JS.
This isn't currently a library you can use, just a proof of concept. It is not yet clear if this technique would actually provide gains, and in fact there are many situations where it would negatively impact performance because we can't start compiling the JavaScript until the Wasm is done compiling. If there isn't high network count contention concurrent would almost always be better. So it is probably best in most cases to continue to ship two files for this reason or look into [Web Packages](https://github.com/WICG/webpackage/blob/master/explainer.md).
## Custom Section
JavaScript is embedded into the WebAssembly file in a custom section named "wasmjs". This was done to allow us to still use streaming compilation via `WebAssembly.compileStreaming()`. Because custom sections are ignored, the single file can be streamed into the compiler as-is. Once it has been compiled we can then access the custom section containing the JavaScript, which is evaluated and passed the WebAssembly.Module instance, letting it finish up the actual instantiation of the Module and provide any JS imports it might need.
## Thanks
The current technique was [suggested by Sander Spies](https://twitter.com/Sander_Spies/status/1019872826696794113).