Home >Web Front-end >Front-end Q&A >What is WebAssembly? A simple understanding of WebAssembly
WebAssembly, or wasm for short, is a new type of code that runs in modern web browsers. It is a new technology for running portable programs in a safe and effective way, mainly for the Web platform. The following article will introduce you to WebAssembly. I hope it will be helpful to you.
What is WebAssembly?
WebAssembly or wasm is a low-level, portable bytecode format for in-browser client-side scripts. It is a new type of code that runs in modern web browsers, and Provides new performance features and effects that are effective for browser downloads and loading.
It is designed to provide an efficient compilation target for low-level source languages such as C, C and Rust.
In fact, WebAssembly is implemented by the browser developers behind the existing JavaScript engine. Essentially, it aims to replace JavaScript as a target for compilers and translators on the web. For example, instead of compiling TypeScript to JavaScript, its developers can now compile to WebAssembly. In short, it's not a new virtual machine, it's a new format for the same JavaScript VM included in every browser. This makes it possible to leverage existing JavaScript infrastructure without using JavaScript.
Why WebAssembly?
If you just want modules written in native languages such as C, C, Java, etc. to run on the browser. We only need a converter to convert the source language into the target language JavaScript.
For WebAssembly, it can directly compile native languages such as C, C, and Java into machine code, omitting converters. Greatly improved efficiency.
The browser achieves a breakthrough in execution efficiency by adding compilation support for a language format.
In addition to running fast, WebAssembly's special binary representation also greatly reduces the size of the code package. At the same time, the loading speed of the browser is improved.
Advantages of WebAssembly:
1. Fast and efficient
WebAssembly is a Portable bytecode format, the bytecode is transmitted in a binary format and due to the structure of the module can be compiled in parallel by the browser for further speedup, allowing it to run at close to native performance. It is designed to provide an efficient compilation target for low-level source languages such as C, C++, and Rust.
2. Portability
Webassembly can be ported to other platforms. This means that if you write software in a language that compiles to WebAssembly, you can run it on .NET. It allows us to reuse existing JavaScript infrastructure on the web.
WebAssembly code can run at near-native speed on different platforms.
3. Readable and debuggable
WebAssembly is a low-level assembly language, but it designs a very regular, human-readable text format , which allows you to write code, view code, and debug code by hand.
4. Security
WebAssembly runs in a sandboxed execution environment and can even be implemented in the existing JavaScript virtual machine. In the web environment, WebAssembly will strictly comply with the same origin policy and browser security policy.
【Recommended related articles】
What is GraphQL? The advantages and disadvantages of GraphQL
The above is the entire content of this article, I hope it will be helpful to everyone's learning. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !
The above is the detailed content of What is WebAssembly? A simple understanding of WebAssembly. For more information, please follow other related articles on the PHP Chinese website!