Blog for Junior Developers C#/.NET

Friday, October 25, 2024

The second hosting model in Blazor is the so-called Blazor WebAssembly, or WASM for short. Initially, Blazor only provided these 2 models, but since .NET 8 it has improved it and added more. In this article, I will introduce you to Blazor WebAssembly.

Introduction to Blazor WebAssembly (WASM)

Introduction


When it comes to Blazor WebAssembly, this is a typical SPA application, where the entire application code is downloaded on the first connection to the server. Hence, this first connection will be a bit longer, and the next ones will be very fast. We can also analyze the pros and cons of this solution here.


Disadvantages


Let's start with the disadvantages:

The application is larger, so you have to wait longer for the first connection. In addition, you have to download WebAssembly, so if it's your first time on a given page, it may take a few seconds for everything to download. This is the biggest disadvantage of WebAssembly. However, in most cases it won't be a big problem, at this point you can display some nice spinner so that the user knows that they have to wait a second or two for the connection. What's more, since .NET 8 it has been improved and I will show you in the next materials how to deal with it so that it is not a problem at all.

The second disadvantage is the lack of compatibility with some older browsers. Browsers must support WebAssembly, which, as I said, may be a problem for some old browsers. In good browsers such as chrome, firefox, edge, opera - it will not be a problem. In these browsers it has been supported for a long time. The problem may appear, for example, in older versions of internet explorer, but there are always some problems there.

The application mainly runs on the client side, hence they consume more client resources such as memory, CPU than server applications.

You also need to keep in mind not to share any secret data, passwords, etc. with the user, because the application code is downloaded to the client. However, I will show you how to design an application in such a case so that this is not a problem. We will use Web API here, just as it is done in the case of SPA applications. So you have nothing to worry about here.


Advantages


Now let's move on to the advantages of Blazor WebAssembly:

The app works in the browser, so it will work smoothly and very quickly after the first launch. There are no delays here either and everything is very user-friendly. Using such an app is a pleasure.

Due to the fact that the application runs on the browser side, we have less load on our server.

The app can also work offline. So if you want to create progressive web apps (PWA), you can also create them in Blazor WebAssembly.


Summary


As for my experience, I have created applications in both Blazor Server and Blazor WebAssembly. It is known that each of these applications will be more or less suitable for a different type of application and it must be adapted to the client's requirements. However, if I had to choose only these 2 models, I would recommend Blazor WebAssembly more, because despite the slower initial application load, the application works very smoothly later, which is very important for users. However, Blazor Server, in my opinion, is a bit lame here, but as I mentioned, I will show you how to deal with these problems and create applications that will satisfy every client.


Blazor School


By the way, if you would like to learn Blazor from the inside, consider joining my online training - Blazor School (more information here - https://blazor-school.com/).

Author of the article:
Kazimierz Szpin

KAZIMIERZ SZPIN
Software Developer C#/.NET, Freelancer. Specializes in ASP.NET Core, ASP.NET MVC, ASP.NET Web API, Blazor, WPF and Windows Forms.
Author of the blog CodeWithKazik.com

Previous article - Introduction to Blazor Server (SignalR)
Next article - Introduction to Blazor Server Side Rendering (SSR)
Dodaj komentarz
© Copyright 2024 CodeWithKazik.com. All rights reserved. Privacy policy.
Design by Code With Kazik and Modest Programmer.