Storing WASM in Web Native Storage

This example demonstrates how to store WebAssembly modules in web native storage and execute them at a later time. We have compiled an add function from C to WebAssembly.

  int add(int x, int y)
    return x + y;

Our Storing WebAssembly Modules guide walks through the code in this example and the source code is available on GitHub.

We will use web native storage in your browser for this example. Please sign in with Fission to get started.

Request and Store

Let's start off by requesting add.wasm and storing it to web native storage. We will make a GET request, convert the Response to an ArrayBuffer, and then store the buffer as a Blob.

List Storage

We have stored add.wasm to a wasm/math directory in web native storage. Let's list the contents of that directory to see if it is there.
name size mtime isFile
It worked! Files are stored in web native storage with their name, size, last modified time and flag that indicates whether they are a file or not.

Load and Run

We can now load our module from storage and ask it to add some numbers.
The module is loaded as an ArrayBuffer and instantiated as a ResultObject with a module and instance. We call the add function off the instance and display the result.

Your Maths are Everywhere

We have published the WASM module and the result of your computation to your web native storage across the web. If you have linked your Fission account on another device, you can open this example and see the results there.
See the Account Linking guide if you haven't linked your account on another device yet.
Storing WASM modules means you only need to request them once. Any app that has access to a user's web native filesystem (WinFS) will retrieve stored modules in the background.
Check out our Introduction to Web Native Apps to learn more about web native compute and storage. Read the web native developer guide to learn more about the web native SDK.