.NET8 improves WebAssembly support in C# and Blazor

.NET 8, the next version of Microsoft’s software development framework, will bring new features and improvements for web developers who use Blazor, a technology that allows writing web apps with C# and .NET. Blazor can run on different platforms, such as WebAssembly, ASP.NET Core, or native client apps.

One of the main enhancements in .NET 8 for Blazor is the ability to combine server-side and client-side rendering with the same component model. This means developers can choose the best rendering mode for each scenario, depending on the performance, interactivity, and scalability requirements. For example, server-side rendering can improve the initial load time and SEO of a web page, while client-side rendering can enable offline support and faster UI updates.

.NET 8 also introduces two new features for server-side rendering: streaming rendering and client interactivity. Streaming rendering allows sending content updates to the browser as they become available, instead of waiting for the entire page to be rendered. This can enhance the user experience for pages that need to perform long-running async tasks. Client interactivity allows adding JavaScript functionality to specific components or pages, without affecting the rest of the server-side rendered app.
Another improvement in .NET 8 for Blazor is the support for rendering components outside the context of an HTTP request. This enables generating HTML fragments from Blazor components, which can be useful for scenarios such as sending automated emails. In the future, Microsoft plans to enable static site generation for Blazor, which can improve performance and security.

.NET 8 also works on optimizing the performance of Blazor WebAssembly, which is a way of running .NET code in the browser using standard web technology. One of the optimizations is the jiterpreter, which is a hybrid mode that combines ahead-of-time compilation and just-in-time compilation. The jiterpreter can speed up the execution of .NET code in WebAssembly by using partial JIT support https://www.infoworld.com/article/3697728/microsoft-net-8-boosts-blazor-webassembly.html. Microsoft claims that it has seen a 20% improvement in UI rendering and a 2x improvement in JSON serialization and deserialization with the jiterpreter.

Other optimizations for Blazor WebAssembly include leveraging the latest WebAssembly specifications, such as SIMD (Single Instruction Multiple Data), which can boost performance for parallel computations. .NET 8 also supports hot reload for Blazor WebAssembly, which allows applying code changes without restarting the app. Additionally, .NET 8 introduces a new packaging format called Webcil, which is more web-friendly and reduces the size of Blazor WebAssembly apps.

.NET 8 also brings stability to QuickGrid, a fast data grid component that was introduced in .NET 7 as a preview feature. QuickGrid can display large amounts of data with features such as sorting, filtering, grouping, and editing. Moreover, .NET 8 adds APIs for monitoring activity on circuits in Blazor Server, which can help free up resources by detecting idle or disconnected clients.
.NET 8 is expected to be released in November 2023. It is currently available as a preview version that can be downloaded from Microsoft’s website . Developers who want to learn more about Blazor can access free tutorials, videos, code samples, and content from Microsoft Learn.