What is Blazor?
Blazor (Browser + Razor) is a new web framework released by Microsoft. It allows you to create browser-based applications using C # and Razor syntax in addition to HTML and CSS.
Previously, anyone using Razor had to launch Razor views on the server, thus generating HTML that could be rendered by the browser. Now, Razor views can be executed client-side.
Since Blazor uses WebAssembly , we don't need to install any third-party plugins or add-ons in the browser to execute the corresponding code. As a result, it turns out that using Blazor, you can create client and server parts of your application in C #. The ability to share code and libraries on the client and on the server makes a developer's life much easier.
Here's some sample code used in Blazor.
Blazor code
Why is there so much buzz around Blazor?
Blazor has gained considerable popularity in a fairly short time. They began to compare it with popular JavaScript frameworks. There is a lot of talk on the internet about the future of client-side web development, and Blazor is also mentioned in those conversations. All this only adds to his popularity. I propose to understand the reasons for this and talk about why so much attention is riveted to Blazor.
As I said before, Blazor's main strength is its ability to develop browser-based applications in C #. In recent years JavaScript (or TypeScript) has been the primary language for developing client-side web applications. That is, if someone is a .NET programmer, in order to develop full-stack applications for the web, they need to learn JavaScript. And with Blazor, you can write both front-end and back-end web applications in C #. For me personally, this is the main strength of Blazor.
Code written for Blazor, unlike JavaScript code, is precompiled into an intermediate format before it reaches the browser. This feature gives us some great features when developing performance-intensive browser applications. Plus, Blazor apps are suitable for solving resource-intensive tasks on the client. For example - to create PDF-files or to make game algorithms work.
But apart from the above, Blazor has other interesting features:
- You don't need browser plugins to make Blazor work.
- When developing for Blazor, you can fully debug your .NET code.
- The framework takes advantage of the latest browser capabilities.
- Blazor maintains a user-friendly interface development model.
- The framework has good browser support.
- Blazor supports dependency injection.
- Using Blazor allows you to share code between the client and server parts of your applications.
Comparison of JavaScript tools and Blazor
And now we got to the very main part of this article. Let's look for an answer to the question of whether Blazor can be a replacement for libraries and frameworks written in JavaScript. Can JavaScript keep its current position? Perhaps anyone interested in the current state of front-end development would like to know the answers to these questions. I believe that it is too early to draw final conclusions, or even to make some assumptions on this score. But to get closer to the truth, we can compare several leading JavaScript libraries and frameworks to Blazor.
▍Blazor vs React Comparison
React is considered by many to be the best library for developing web components. While it is difficult to compare React and Blazor, we must admit that React is a carefully crafted library that has proven its worth for developing real projects. A powerful community of programmers has formed around React.
The React ecosystem is full of libraries and frameworks that make it easy to develop optimized React apps. These libraries and frameworks make React a “universal language” that can be used to create applications for the web, for the command line , for iOS and Android , and for the desktop .
Blazor is relatively new compared to React. But don't forget that Blazor has a solid Razor system behind it. Therefore, we cannot say that Blazor is something completely unknown to programmers. In addition, because Blazor uses C #, it makes it easier and faster for .NET developers to learn this framework. While React has improved over time, it gives developers a lot of opportunities, and while React has many strengths, Blazor, despite its very young age, also has something remarkable:
- Blazor projects, like React projects, can be deployed as static files.
- You can use NuGet packages in Blazor apps.
- When using Blazor on the client and on the server, you can use the same code (of course, this is also true when using JS / TS).
- Blazor has built-in routing mechanisms, for validating user input, for processing forms.
This is just a small selection of Blazor's capabilities. But, if you focus on the current situation, we can say that if a certain team confidently uses JavaScript, then they should definitely just use React. On the other hand, Blazor is a great option for someone with a better command of .NET than JavaScript while starting a new web project.
▍Blazor vs Angular Comparison
The JavaScript framework Angular is also popular for developing single page applications. If you compare it with the React library, you will find that it includes more standard features. Angular provides the client application developer with an MVC architecture to simplify the process of building and testing projects. If you compare Angular and Blazor, then it turns out that Angular holds a solid place in front-end development as a well-known and stable framework suitable for building real applications. In addition, Angular fully supports progressive web applications, while Blazor's server-side engines still need to evolve in this direction. Moreover, since Angular uses TypeScript, this framework is closer and more understandable for C # programmers than JavaScript-based frameworks and libraries.Given all the strengths of Angular, I see no reason for someone with a good knowledge of TypeScript to choose Blazor.
Outcome
Blazor is certainly an interesting project that, despite the fact that it appeared relatively recently, deserves some attention. And the question of whether it can replace JavaScript tools in front-end development is still open.
Have you tried Blazor?