Are browsers no longer able to run C/C++, Go... JavaScript?

Are browsers no longer able to run C/C++, Go... JavaScript?

Daily short news for you
  • For over a week now, I haven't posted anything, not because I have nothing to write about, but because I'm looking for ways to distribute more valuable content in this rapidly exploding AI era.

    As I shared earlier this year, the number of visitors to my blog is gradually declining. When I looked at the statistics, the number of users in the first six months of 2025 has dropped by 30% compared to the same period last year, and by 15% compared to the last six months of 2024. This indicates a reality that users are gradually leaving. What is the reason for this?

    I think the biggest reason is that user habits have changed. They primarily discover the blog through search engines, with Google being the largest. Almost half of the users return to the blog without going through the search step. This is a positive signal, but it's still not enough to increase the number of new users. Not to mention that now, Google has launched the AI Search Labs feature, which means AI displays summarized content when users search, further reducing the likelihood of users accessing the website. Interestingly, when Search Labs was introduced, English articles have taken over the rankings for the most accessed content.

    My articles are usually very long, sometimes reaching up to 2000 words. Writing such an article takes a lot of time. It's normal for many articles to go unread. I know and accept this because not everyone encounters the issues being discussed. For me, writing is a way to cultivate patience and thoughtfulness. Being able to help someone through my writing is a wonderful thing.

    Therefore, I am thinking of focusing on shorter and medium-length content to be able to write more. Long content will only be used when I want to write in detail or delve deeply into a particular topic. So, I am looking for ways to redesign the blog. Everyone, please stay tuned! 😄

    » Read more
  • CloudFlare has introduced the pay per crawl feature to charge for each time AI "crawls" data from your website. What does that mean 🤔?

    The purpose of SEO is to help search engines see the website. When users search for relevant content, your website appears in the search results. This is almost a win-win situation where Google helps more people discover your site, and in return, Google gets more users.

    Now, the game with AI Agents is different. AI Agents have to actively seek out information sources and conveniently "crawl" your data, then mix it up or do something with it that we can't even know. So this is almost a game that benefits only one side 🤔!?

    CloudFlare's move is to make AI Agents pay for each time they retrieve data from your website. If they don’t pay, then I won’t let them read my data. Something like that. Let’s wait a bit longer and see 🤓.

    » Read more
  • Continuing to update on the lawsuit between the Deno group and Oracle over the name JavaScript: It seems that Deno is at a disadvantage as the court has dismissed the Deno group's complaint. However, in August, they (Oracle) must be held accountable for each reason, acknowledging or denying the allegations presented by the Deno group in the lawsuit.

    JavaScript™ Trademark Update

    » Read more

Issues

I used to wonder if browsers could run languages other than JavaScript, such as Python or Golang. Because we all know that JavaScript has been the dominant language in browsers for a long time, it is the primary language for interacting with browser components.

JavaScript is powerful, but it also has its drawbacks. It consumes a lot of memory and can struggle with heavy computational tasks, causing the main thread to freeze and making user interactions with web pages terrible.

Nowadays, as user experiences have evolved, especially with the emergence of VR and NFT applications, websites need to handle more. JavaScript is currently able to handle this, but it is time for us to have new tools to support it.

Introduction to WebAssembly

What is WebAssembly?

WebAssembly (WASM) is a binary instruction format that runs in browsers or on servers. It is designed for performance and security. WebAssembly can be compiled from other programming languages such as C/C++, C#, Rust, Go, and many others.

What can WebAssembly do?

WebAssembly is used to execute heavy and computationally intensive tasks of web applications. This allows JavaScript to focus on handling the interactive aspects of the browser while letting WebAssembly handle the heavy lifting. WASM was initially created for the web, and it has many use cases such as image/video editing, gaming, VR, simulation on the web platform, and more.

Will WebAssembly replace JavaScript?

No! Or at least, it cannot replace JavaScript yet. As mentioned earlier, WebAssembly replaces JavaScript for CPU-intensive tasks, but JavaScript still cannot be replaced for user interaction.

The future of WebAssembly

Although WASM is still relatively new, with the development of current websites, the search for an optimization tool, WASM is becoming a promising candidate. WASM has been and is being used by applications like AutoCad and Figma for a long time. Let's look forward to the future advancements of WebAssembly.

Using WebAssembly

WebAssembly supports various programming languages. You can see a list at https://webassembly.org/getting-started/developers-guide/.

To use WebAssembly, the code of other programming languages is compiled into the binary format with the .wasm extension. Then, import the file into HTML code and start using the modules you have written. The following example demonstrates how to write a module in Go and use it with WebAssembly.

First, create a file named hello.go with a simple main function that prints "Hello, WebAssembly":

package main

import "fmt"

func main() {
  fmt.Println("Hello, WebAssembly!")
}

Then, build the file into the .wasm format for browser usage:

$ GOOS=js GOARCH=wasm go build -o main.wasm

To run the .wasm file in the browser, you need to use a .js file for support. For Golang, you can find it at:

$ cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" .  

Now, create an index.html file to use wasm:

<html>
<head>
  <meta charset="utf-8" />
  <script src="wasm_exec.js"></script>
  <script>
    const go = new Go();
    WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then((result) => {
      go.run(result.instance);
    });
  </script>
</head>
<body></body>
</html>

Then, run an HTTP server. Here, I will use the http-server package:

$ http-server .  

Access http://127.0.0.1:8080 in your browser, and you will see "Hello, WebAssembly!" printed in the console.

Let's add a function to calculate the sum of two numbers in Golang and call it from JavaScript:

package main

import "syscall/js"

func main() {
	js.Global().Set("wasmAdd", js.FuncOf(add))
	<-make(chan bool)
}

func add(this js.Value, args []js.Value) interface{} {
	return args[0].Int() + args[1].Int()
}

syscall/js is the Go library that supports WebAssembly. I created an add function that returns the sum of two parameters.
js.Global().Set("wasmAdd", js.FuncOf(add)) is used to set the Go add function as the wasmAdd function to be used in JavaScript.
<-make(chan bool) prevents the Go program from exiting when it finishes executing.

Now, recompile the .wasm module using the steps above. Refresh the browser, and from the console window, call the wasmAdd(1,2) function:

wasmAdd(1,2)

It's that simple, isn't it!

Conclusion

WebAssembly is a portable binary instruction format that runs in browsers or on servers. WebAssembly can be compiled from other programming languages such as C/C++, C#, Rust, Go, and many others.

WebAssembly is used to execute heavy and computationally intensive tasks of web applications. It was not created to replace JavaScript.

Premium
Hello

Me & the desire to "play with words"

Have you tried writing? And then failed or not satisfied? At 2coffee.dev we have had a hard time with writing. Don't be discouraged, because now we have a way to help you. Click to become a member now!

Have you tried writing? And then failed or not satisfied? At 2coffee.dev we have had a hard time with writing. Don't be discouraged, because now we have a way to help you. Click to become a member now!

View all

Subscribe to receive new article notifications

or
* The summary newsletter is sent every 1-2 weeks, cancel anytime.

Comments (3)

Leave a comment...
Avatar
Tiến Đức3 years ago

Assem vẫn còn chưa phổ biến lắm

Reply
Avatar
Trịnh Thị Anh3 years ago

Có hướng dẫn với python không ah?

Reply
Avatar
Xuân Hoài Tống3 years ago

Hiện tại có vẻ như Python vẫn chưa chính thức hỗ trợ cho ưebassembly. Tuy nhiên có một số thư viện không chính thức đã được phát hành bạn có thể tìm hiểu thêm xem sao!

Avatar
Ẩn danh3 years ago

Bạn ra thêm bài viết về webassembly đi mình cũng đang tìm hiểu cái này

Reply
Avatar
Xuân Hoài Tống3 years ago

B cần tìm hiểu thêm gì mình sẽ nghiên cứu thêm