What is Blazor?
What if the client code and server code could not only live under one roof but learn to share and even speak the same language?
A More Unified Project
One of the main selling points of Blazor mentioned above is that the front-end and backend of an application can share many of the same code and libraries. Since Blazor is built on top of .NET Standard, client code can make use of any existing .NET library. Furthermore, all of the application logic can now be shared across client and server. This means both sides can now make use of the exact same classes, services, and controllers. This leads to much less duplicated code and logic across both sides since they can both pull from the exact same resources.
Blazor makes use of Razor components. Anyone familiar with that mix of HTML and C# will have no problem adapting to Blazor. Razor components are flexible, reusable, testable, and shareable. Also, Blazor applications can be built using Visual Studio. VS is a popular and very powerful IDE also built by Microsoft. Since both are Microsoft products, you can imagine they work very well together.
As mentioned, Blazor is currently available in two hosting models: Blazor WebAssembly and Blazor Server. Each will be detailed below. Additionally, there are plans for Blazor PWA (which supports progressive web applications) and Blazor Hybrid (a platform-native framework that renders using web technology). Blazor Native, a platform-native framework that renders a platform-native UI, is also being considered. The hosting models provide great flexibility and fit most situations.
Blazor is supported by most major web browsers, including Apple Safari, Google Chrome, Microsoft Edge, and Mozilla Firefox. But in reality, any modern web browser that supports WebAssembly is able to run a Blazor application.
Unfortunately, nothing is perfect, and Blazor is not without its faults.
Microsoft has invested a lot of resources into developing Blazor and seems to have a lot of plans for its future. However, it is had to trust a young framework when projects like this are dropped at the tip of a hat by large tech companies. Google has killed off many beloved features, and people are still sore about how Microsoft pushed Silverlight hard, only to unceremoniously drop it with little warning. Developers have a long memory and are, with good reason, slow to fully commit to new technologies like this. This can make it hard.
Blazor is now officially part of .NET 5, which is a terrific sign for Microsoft’s commitment to and investment in the technology. However, Microsoft also decided not to create their own official component library, as they have with NuGet and C#. Instead, they chose to leave component libraries to third-party developers. While this can always change, it does send a bit of a mixed message. Is Microsoft genuinely committed to the framework? Is this decision merely to focus resources on developing Blazor itself? We’ll never really know until it goes one way or the other.
Blazor is still very young, having been around only four years. While both Blazor WebAssembly and Server have reached general availability and are considered production-ready, they are largely untested and not nearly as mature as Angular or React. Since Blazor is so young, Microsoft is also continuously updating the framework and making significant changes, leading to headaches in a production environment. There are also no large projects that made use of Blazor. Since it has such a short track record and few accolades, it can be hard to trust as the basis for your larger projects.
Microsoft has invested a lot of resources into developing Blazor and seems to have a lot of plans for its future.
Blazor currently has two hosting models that are production-ready. Each excels in certain aspects, so choosing the correct model for the project requires great thought and consideration.
All work is offloaded to the client, and the application can leverage all client resources and capabilities. Because the entire application exists in the client, there is no server-side dependency. This means Blazor WebAssembly projects can be standalone or hosted and serverless deployment is possible through either a CDN or Docker container.
However, Blazor WebAssembly is not without flaws. Because the application uses WebAssembly and runs entirely on the browser, it is limited to the browser’s capabilities. Considerations may have to be taken to make the application completely cross-platform. Additionally, like most SPAs, Blazor can take a long time initially due to the large initial payload. Blazor does try to optimize the size of the payload, however. Finally, .NET runtime and tooling support is less mature.
Since Blazor Server has a much smaller initial payload, the application loads much faster than with WebAssembly. .NET and C# code do not need to be served to the client and only code to render the view and update the view is necessary. Additionally, since the runtime and code are all server-based, all server capabilities can be leveraged and .NET tooling and debugging work as expected for any regular web application.
However, since every single interaction by the user and update to the view require communication with the server, latency can be much higher. Additionally, since every event and view update require the server, the application has no offline support. If the SignalR connection fails for any reason, the application will simply stop working. The server is also now responsible for maintaining an active connection to every client and must act on every action taken by each client. This can put a great load on the server and make scaling for many users difficult. Finally, because an active SignalR connection is required, serverless deployments are not possible.
This has been a high-level overview and description of Microsoft Blazor, an exciting new technology in the web UI framework world. Blazor attempts to bridge the gap between client and server and provide the developer with a more unified platform for creating web applications. With two production-ready models and many more to come, Blazor has a bright future. I am already impressed with what Blazor has accomplished and am excited to see what comes next. Personally, I don’t think the technology is quite ready for prime time but could very well be in the next few years. Will we one day see Blazor compete with the likes of juggernauts like Angular or React? Only time will tell.
Interested in diving deeper into Custom App & Web Development? Click here to read more blog posts from Tallan. We also have multiple live educational webinars centered around our funded App Innovate opportunity, providing attendees with a chance for direct Q&A with our experts. Click here to view our current calendar.