Before the Electron project, cross-platform desktop application development was not particularly easy, because developers often had to maintain separate codebases for each operating system. Even though there were some generic APIs to build cross-platform applications, creating custom GUI elements was difficult.
However, Electron applications consume above average resources on user’s computers, which means many developers are looking for lightweight Electron alternatives. In this article, I will be discussing two alternatives to Electron: Tauri and Neutralino.js. I will also show you how to install and use these frameworks.
What is Electron?
If we need to show a message box, we can use the
dialog.showMessageBox method from the Electron API. We don’t need to worry about the platform-specific code because Electron has dialog box implementations for Linux, macOS, and Windows.
Advantages of Electron
Nowadays, most developers make their cross-platform applications with Electron because of the following impressive advantages:
Electron provides a flexible abstraction for native operating system features. Therefore, developers can maintain a single codebase for their cross-platform application that will run on most popular platforms.
Rapid feature delivery
Creating user interfaces with HTML and CSS in Electron is a piece of cake; these web technologies give you the freedom to create any custom GUI element. Additionally, Node.js has a massive ecosystem of libraries so you can add native-like features very quickly.
Electron was initially released about eight years ago, so it has a strong user base and community. There are beneficial built-in features such as auto updates, too. Reputable companies such as Microsoft choose Electron for building their cross-platform applications. For example, Visual Studio Code, Teams, and Skype were built on top of Electron.
Hidden issues in Electron
While overall impressive, the Electron framework has several critical performance issues.
Electron bundles Chromium and Node.js into the final application package, so even if you are writing a simple and lightweight application by carefully choosing frontend libraries and frameworks, your application will become bloated.
Chromium and Node.js are complex projects, and these modules will consume above-average resources on your computer. In other words, applications built with Electron will take tons of physical memory and disk space.
Furthermore, Electron applications drain your laptop’s battery quickly due to high resource consumption. The cross-platform applications made with Electron often become bloatware due to Electron’s critical performance issues mentioned above.
Powerful hardware can hide this drawback from the average user. However, once users start running multiple Electron applications, it’s easy to feel this hidden performance issue.
Alternatives for Electron
Some time back, several alternatives such as Electrino and DeskGap arrived as solutions for Electron’s performance issues. Both projects tried to reduce the final bundle size by using the operating system’s webview instead of Chromium. Unfortunately, these two projects couldn’t complete with the matured Electron framework.
However, there are two trending lightweight alternatives for Electron: Tauri and Neutralino.js. Both projects try to solve Electron’s performance issue by replacing both Chromium and Node with better, lightweight alternatives.
Both projects use the well known webview library for rendering HTML and CSS instead of Chromium. The webview library uses the existing web browser component for rendering. For example, it will use gtk-webkit2 on Linux-based platforms, Cocoa Webkit on macOS, and Edge/MSHTML on Windows.
What is Tauri?
Tauri is a lightweight, cross-platform desktop application development framework written in Rust. Developers can make the frontend of a Tauri application by using their preferred frontend framework.
Let’s write a simple cross-platform application with Tauri.
Tauri applications can be built on any popular platform. In this demonstration, I built on Linux.
First, we need to install the required libraries by entering the following command in the Terminal:
$ sudo apt update && sudo apt install libwebkit2gtk-4.0-dev \ build-essential \ curl \ wget \ libssl-dev \ appmenu-gtk3-module \ libgtk-3-dev \ squashfs-tools
After that, we need to install the Rust compiler and the Cargo package manager:
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Finally, we need to install Tauri CLI (make sure you already have Node.js and a package manager):
$ npm install -g tauri
A fresh Tauri application can be created by entering the following commands:
$ mkdir tauri-app && cd tauri-app $ tauri create
Once you enter the
tauri create command, the CLI will ask a set of questions for configuring the application. In this example, default values were used. The application name is
tauri-app/src-tauri directory consists of the backend code of your application. You can place your frontend code into the
tauri-app/dist directory. For now, I created
tauri-app/dist/index.html and entered the following HTML:
<h1 style="padding-top: 45vh; text-align: center;" >Hello Tauri!</h1>
We can launch our application by simply entering
tauri dev. Since I am not using a development server, I had to set
devPath to the
../dist directory in the
Releasing a Tauri app
Tauri lets you create a single binary of your application for each platform. It can be done by simply entering
tauri build command. But, if you need to make binaries for Linux, you have to run this command from a Linux computer.
What is Neutralino.js?
Let’s write a simple cross-platform application with Neutralino.
Neutralino doesn’t require any additional libraries for application development. All you need to do is install its CLI on any operating system:
$ npm install -g @neutralinojs/neu
A fresh Neutralino application can be created using the following command:
$ neu create neutralino-app
app/index.html) of this example application has the following content:
<h1 style="padding-top: 45vh; text-align: center;" >Hello Neutralinojs!</h1>
The application can be launched by simply entering the
neu run command.
Releasing a Neutralino.js app
We can release our application for others by entering
neu build command. The command will make binaries inside the
Neutralino doesn’t offer single binary creation support as Tauri does. It will always create a single resource file along with the platform-specific binary.
The same application took the following resources on Electron, Tauri, and Neutralino.js. The measurements are done on the Linux platform:
|Bundle size (uncompressed)||200mb||8mb||2mb|
|Physical memory usage||~100mb||~50mb||~50mb|
Electron, Tauri, and Neutralino.js will render an entire application inside a web browser. However, the rendering process of a web browser is complex. There are several steps before the drawing process of web-based GUI elements.
First, HTML, CSS content will be parsed. After that, the browser will make the DOM tree with parsed results. Finally, the web browser will draw the render tree that is made by combining style rules and the DOM tree.
Therefore, these frameworks are not suitable for very large applications. In such situations, going native or using a truly native framework such as Flutter could be a wise choice.
According to the above comparison, Tauri and Neutralino.js perform better than Electron. Electron applications consume a lot of disk space because each application is bundled with Chromium and Node. On the other hand, Tauri and Neutralino.js have surprisingly lightweight bundle sizes because those frameworks are reusing the user’s operating system’s system web browser library.
Electron allows you to ship a desktop application comfortably, but it will create critical performance issues that will cause frustration of users. Therefore, it’s time to look for an alternative.
LogRocket: Full visibility into your web and mobile apps
LogRocket is a frontend application monitoring solution that lets you replay problems as if they happened in your own browser. Instead of guessing why errors happen, or asking users for screenshots and log dumps, LogRocket lets you replay the session to quickly understand what went wrong. It works perfectly with any app, regardless of framework, and has plugins to log additional context from Redux, Vuex, and @ngrx/store.