WebAssembly is a new portable, size- and load-time-efficient binary format
suitable for compilation to the web. [1] It's a new technology tendency and
reached consensus by Chrome, Edge, Firefox, and WebKit. [2] It will affect
the developer's choice between web and native (or Weex). However, it will
not change the structure of the native developments, and can be complement
with Weex.

I have studied this technology for some time now. Here is my views on how
to use the WebAssembly in Weex:

1. Add a js service to load WebAssembly module.

  loadWebAssembly('path/to/lib.wasm').then(instance => {
      // ...
  })

2. Offer a native module to compile wasm binary files.

  const wasm = weex.requireModule('wasm')
  wasm.load('path/to/lib.wasm', instance => {
      // ...
  })

3. Support to use <script type="module"> directly in ".we" and ".vue"
syntax.

  <script type="module" src="path/to/lib.wasm"></script>


For the first proposal, we can use js service to create a global methods
"loadWebAssembly", which can load and compile the wasm binary file into
WebAssembly module. Acrooding to the official defined JS API [3], the
"loadWebAssembly" should also return a Promise.

I have already implement it on my personal repo [4]. But I still have some
concerns:

  * I use the "stream" module to fetch wasm files, but the data in the
response must be "text" or "json", can't be binary. I have to convert the
"text" to ArrayBuffer manully. It's inefficient, and it should be done in
the native.
  * It's hard to achieve the cache.


For the second and third proposal, it's much efficient than the first and
much harder to achieve.

It's a little radical. Feel free to discuss the proposals, I will explain
the details.

-------

[1] http://webassembly.org/
[2]
https://lists.w3.org/Archives/Public/public-webassembly/2017Feb/0002.html
[3] http://webassembly.org/docs/js/
[4] https://github.com/Hanks10100/weex/tree/wasm/html5/services/wasm

-------

Hanks

Reply via email to