Isn't it ironic? On one hand, you've kept hearing/reading have all this talk about WebAssembly and what a game changer for the web it is. Yet, on the other hand, few developers are actually leveraging it in their projects? There's all this hype around the new way of assembling code in any language and running it right in the web browser, yet everyone's still a bit hesitant about using it. Are there any truly compelling use cases for WebAssembly?
Why would you use it? What are its primary use cases?
For now, what you do know are its “selling points”, that everyone's blowing the trumpet about:
- it enables you to build reliable, dynamic, faster websites
- it's now shipping in all major browsers
- it enables you to write your piece of software once and then have it run on... every platform with a browser
- it's a “revival” of the smart client software development
And where do you add that it requires a huge shift in mentality, as well: using the browser for tasks that developers are used to performing in the back-end.
Now, let's shed some light here and bring forward the most compelling use cases for WebAssembly:
1. Writing Faster Code
And writing “almost fast as native code for web browsers” has been one of developers' ever-present goal.
Well, yes: WebAssembly does enable you to write faster code.
- benchmarks have shown WebAssembly to be 10% slower than C code. Still, many consider it as a too little compromise for all the flexibility and portability they get in return.
2. Client-Side Compression: One of the Primary Use Cases for WebAssembly
Just think of the tones of convenience that such a use case comes bundled with.
Let's take this hypothetical user who takes a photo on his/her phone and then uploads it on a website. In that case, it's the server that normally handles the compression part: the user uploads the image at a default maximum resolution, then the server compresses it.
When using WebAssembly all this compression happens in the... browser. The result: fewer server resources and data/bandwidth used...
You get to run your web apps using the client's CPU instead. Compared to the “old way”, where you would access the server first, then send the result to the client.
4. Compiling Existing Applications for the Browser
Another one of the compelling use cases for WebAssembly is this: compiling your current apps so that they run on the browser.
A possible way to do this is by writing your existing apps in a managed language that has a large runtime. Take for instance a scenario where you'd compile Photoshop for the web browser.
That, of course, if you don't have anything against sending an oversized file over each user's network.
5. Compiling & Accessing C/C++ Libraries
… and compiling Rust, I must add.
“What is WebAssembly good for?” To access C/C++ libraries for a wide range of operations:
- digital media processing
- physics simulation
And, of course, to compile C/C++ and Rust (or other statically typed languages) to a new format, to be easily run in the web browser. All that with a low runtime, so that you can reap the benefits of predictable performance.
6. Moving from Desktop-Only to Browser-Based Applications
WebAssembly marks the “extinction” of the last desktop-only apps.
From VR/AR apps to apps with heavy data usage, to photo and video editors, to games with complex system requirements, they can all be run in the web browser now.
Just imagine all the possibilities that WebAsembly unlocks: it enables you to take code from any language and run it in the web browser. Moreover, since it's a compile target, it “plays nicely” with other languages on the web: C++, Rust, C...
And this leads us to the required shift in mentality mentioned at the beginning of this post: using technology for operations that would normally be performed in the back-end, but which, in this case, involve the web browser...Image by Rani Suarni from Pixabay
We do Web development
Go to our Web development page!