♪ Hello, everyone. I'm Shivai Lamba. I'm Wasim Edge Ambassador and also a TensorFlow.js SIG and Working Group Lead from India. Welcome to my talk at React Advanced. I'm presenting virtually from India. The title of my talk is server-side rendering using Web7b, so let's get started.
The first thing we'll talk about is how do we actually achieve server-side rendering. Now, the traditional ways is either to, let's say, use a React framework like NestJs that actually supports server-side rendering out of the box, or, if you are one of those engineers who would want to set up a server-side rendering manually, you could create a fresh Redux store on every request that gets sent out and then get this data out of the store and perform the server-side rendering, or another alternative way is also to actually set up a Express server that can be used to serve the contents from the build directory as static files to your front end.
So, first, before we move on to how you can achieve server-side rendering with WebAssembly, let's talk about WebAssembly a bit more. So, WebAssembly is a language that is neither related to web directly or related to the assembly language itself. What it is is really an efficient, low-level bytecode that is highly performant and is portable, secure, and language-agnostic compilation-tacked. So that means you can basically take any of your highly performant programming languages like C++, or even scripting languages such as Python or Go, and compile it into a WebAssembly bytecode that can be directly used. Now, why has it been so popular is that it can basically reduce some of the disadvantages that we have in terms of performance, especially with JavaScript. And can overcome those performance limitations by using the more performant programming languages like C++ or Rust, and converting them into WebAssembly, and then running them on the browser alongside JavaScript. And now WebAssembly is not just limited to the frontend or the browser, and finds a lot of different use cases in server-side and cloud applications as well.
And what is Wasmage? So Wasmage is a lightweight WebAssembly runtime that is primarily focused on building a lot of cloud-native and edge-based applications, and Wasmage is currently a CNC, which is the Cloud Native Computing Foundation Sandbox project. So, the question is that, how can WebAssembly be used to actually implement the server-side rendering? So, Wasmage, as we mentioned, it's the runtime for WebAssembly, especially for edge devices. The Wasmage JavaScript SDK runtime actually provides a lightweight and high-performance container, which can run both JavaScript and also the React server-side functions on edge servers. So let's say if you have very limited resources and very less computation power, then you can run these lightweight WebAssembly containers on edge applications and still be able to have performance functions being run very smoothly. And the Wasmage Quick JS, which Quick JS is basically very similar to how V8 functions, so it's a JavaScript engine, and the Wasmage Quick JS engine is able to actually render React app-based components on the server-side and then basically send that rendered HTML as a string to the browser. And it primarily supports both the static-side rendering and also the streaming rendering that is provided from the server-side. But the biggest question is that why should we use WebAssembly in the first place to implement server-side rendering? Because we already have such popular frameworks such as Next.js and also you can set it up manually with Node.js. There are primarily two different reasons I'd like to point out why WebAssembly is useful. Now, compared to the standard approach in which the V8 runs, it uses Node.js and a Linux-based environment. Wasmage and especially WebAssembly has a much smaller footprint in terms of the overall size and how quickly you can actually spin up a WebAssembly-based container. So in terms of performance, it's a lot more faster and especially when you're working with very limited resources on an Edge application or an Edge device. And this does help with more improved load times and performance gains, especially if you're running your applications on the Edge. And secondly, the Wasmage also provides isolation and protection because of how WebAssembly manages memory by providing a sandbox layer around whatever application that you're using with WebAssembly. So that means that the Wasmage implementation for server-side rendering is able to basically execute whatever code is being run in that sandbox environment that is the footfall for how WebAssembly actually works. And that's one of the biggest benefits of performance and both in terms of privacy as well.
Comments