WebAssembly And Progressive Web Apps: The Perfect Pair

WebAssembly And Progressive Web Apps: The Perfect Pair

It has been more than 25 years since web technologies initially appeared in the late 1980s and early 1990s. Since then, a slew of new technologies, competitors, and products have joined the market, fighting for the incalculable number of people who browse the internet every day.

The quest toward making the browser a tool with which users may engage has taken numerous shapes. From the early days of JavaScript to the advent of Adobe Flash and Microsoft's SilverLight, it's clear that interaction in the browser has enough usefulness (and revenue) that firms are ready to invest in improving their capabilities.

The early web was a platform for document reading. Engineers devised clever methods to utilise JavaScript to mimic more complicated desktop programs. We are seeing rich apps created in JavaScript that use methods like hiding/showing regions of the text and dynamically filling sections with data retrieved from an HTTP API. Chat clients, company management software, word processors, and even code editors are examples of this.

The need for Web Application

When you question why these complicated programs, some of which have a history of being platform native applications, are being built (or redesigned) as web-based applications, the cost is frequently brought up.

Regarding online apps, the concept of "writing once and deploying everywhere" is far from a meme. It's as easy as that: if your device has a contemporary web browser, it can execute a web application.

However, there are several issues when it comes to web applications. They are:

  • JavaScript's maintainability in the context of complex web applications.

Although JavaScript modules have made it easier to construct maintainable code from a syntactic standpoint, most programmers will build major projects in a language such as TypeScript (while a superset of JavaScript, the inclusion of types makes it very different in its usage). The difficulty is that the JavaScript written is rarely the JavaScript that the browser runs and JavaScript is not an optimum compiler target.

  • The browser's features, such as significant filesystem access for persistence or access to lower-level devices

These APIs are not available in all browsers and on all platforms. Browsers in which these works are not standardised can be cumbersome to target using JavaScript.

Issues with dynamically loaded scripts and the overall lax security model

Dynamically loaded scripts are not loaded synchronously by default. These can have adverse effects on the execution of the application making it slow and unstable.

What is Web Assembly and How does it solve these issues?

WebAssembly (Wasm) emerged as a solution to address some of the challenges faced by web developers when building complex applications. JavaScript, although widely used, posed concerns regarding maintainability in large projects. While JavaScript modules improved code organization, many developers turned to languages like TypeScript for major projects due to its enhanced typing system.

WebAssembly introduces a new approach. It's a binary instruction format that serves as a portable compilation target for high-level languages like C++, Rust, and others. Unlike traditional JavaScript, WebAssembly code is closer to machine code, making it more efficient for browsers to execute. This addresses the issue of JavaScript not being an optimal compiler target.

Additionally, WebAssembly provides a solution to the inconsistency in browser features. Instead of relying on browser-specific APIs for filesystem access or lower-level device interaction, WebAssembly allows developers to compile their code to a common format that works consistently across different browsers and platforms. This standardized approach simplifies targeting various browsers, avoiding the challenges posed by non-standardized APIs.

Moreover, WebAssembly improves performance by supporting synchronous loading of scripts, overcoming the issues associated with dynamically loaded scripts in traditional JavaScript. This synchronous loading enhances the application's execution speed and stability.

Limitations of WebAssembly

WebAssembly also comes with some issues. There are these limitations to WebAssembly:

Limited DOM Access: WebAssembly has restricted access to the Document Object Model (DOM), making it reliant on JavaScript for interactions with web page elements.

No Garbage Collection: Unlike JavaScript, WebAssembly does not have built-in garbage collection, placing the responsibility on developers to manage memory manually.

Debugging Challenges: Debugging WebAssembly can be more complex than debugging high-level languages due to the lower-level nature of its binary format.

Limited Browser Integration: While major browsers support WebAssembly, its integration may not be as seamless as JavaScript, potentially causing compatibility issues.

Learning Curve: Developers familiar with higher-level languages may face a learning curve when working with WebAssembly's lower-level concepts and syntax.

What are Progressive Web Apps (PWA)?

Progressive Web Apps are apps built using web technologies such as HTML and are designed to run on any device that can run a modern standard-compliant web browser. They may be installed on a device if they fulfil specific browser criteria.

They will have an icon and will inherit the window decorations and controls from the original OS.

Unfortunately, installed web apps do not yet have an API to manage OS window menus (such as the global menu in MacOS or the window context menu in Windows). However, such possibilities may emerge in the future.

The mere presence of an application on your smartphone does not imply that it is "progressive." To manage duties such as network caching and receiving push notifications, a "progressive web application " installs a background process that runs even when the program is stopped.

Limitations of PWA

As web apps began to dominate native application space, it became clear that the limits of browser APIs and a lack of lower-level access limit their ability to replace native programs.

Consider the use case of Visual Studio Coding, a popular code editor. Because it cannot access the filesystem, handle network ports, or communicate with terminals, it cannot be distributed as a pure web application.

There are several examples of comparable programs that demand greater system API access but cannot obtain it from existing browsers, so they package and deploy their browser.

As a result, you wind up running many instances of Chromium/Webkit/Webview forks that are precisely tuned to the needs of the programs they cover.

Perhaps in the future, the browser will broaden what web apps can access and we will see sophisticated desktop programs distributed via the web utilising the. app domain.

The Native vs Web Argument

To be clear, Web Assembly will not answer all of the difficulties raised in the web vs native debate. It will, however, enable a greater proportion of enterprises and application engineers to consider the web when considering their native device experience — given that system APIs accessible by the browser are not a constraint.

Performance is a typical reason why online apps are not favoured. JavaScript, as we all know, is a single-threaded programming language. Web Workers can be used, however, they are difficult to use and so neglected.

Non-game native programs, whether desktop or mobile, generally feature a UI thread dedicated to UI work and any number of worker threads to accomplish tasks on.

This implies that the application's tasks can be split over several physical CPU cores rather than being limited to a single core.

Because Web Assembly is a low-level compile target for higher-level languages, apps can employ OS threads.

This implies that programmers may create web apps in languages with higher parallelism support (Rust, Go), and improved thread usage will result in a smoother user experience, as well as enhanced accessibility for people with lower-end hardware.

However, Web Assembly will not solve all performance difficulties because certain native technologies are hardware accelerated (GPU rendered) and hence highly optimised. On the other hand, intelligent CSS use and an increasing need for GPU acceleration on the web will cause that gap to close over time.

When you look at UI frameworks, you will find many examples of cross-platform and platform-specific implementations.

Windows has its WinForms, WPF, and Metro APIs. Apple has its Swift-based UI kits. Linux will use GTK, Android with its Java implementations and iOS with its implementation.

PWA and Web Assembly work hand in hand

So, what is the solution for developers to make sure they develop web applications that run smoothly and is cost effective? Simple, just let WebAssembly and. PWA (Progressive Web Apps) to work togehter to create powerful, fast, and efficient web applications. With WebAssembly, a low-level assembly-like language that can be used as a compilation target for languages such as C, and C++, performance code can be executed in the browser. On the other hand, PWA is a set of best practices that enables web apps to function like native apps, complete with features like installation on the home screen, push notifications, and offline support.

When used together, WebAssembly and PWA provide a way to execute highly efficient code that is essential for performance within an application. This allows for a smooth and speedy user experience. For instance, tasks that demand high computational power such as image processing, complex computations or data manipulation can be offloaded to WebAssembly modules. This way, other parts of the application can still benefit from PWA capabilities.

Conclusion

The web's progressive growth appears to indicate that it has the potential to challenge the dominance of native UI frameworks and mobile/desktop apps. Deploying native programs across various platforms, from Linux to iOS, may be costly. More extensive browser capabilities are especially enticing since they will make Web Assembly and Progressive Web Apps (PWAs) more appealing and reduce the need to build native apps.

Indeed, the evolution of #webtechnologies has been phenomenal! As Steve Jobs said, "Innovation distinguishes between a leader and a follower." ???? Let's continue to innovate and shape the digital landscape! #TechEvolution #InnovationIsKey??

要查看或添加评论,请登录

AResourcePool的更多文章

社区洞察

其他会员也浏览了