BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News ASP.NET Core 9 Preview 5: Static Web Optimization, Blazor Additions, New Project Template and More

ASP.NET Core 9 Preview 5: Static Web Optimization, Blazor Additions, New Project Template and More

Recently, Microsoft released .NET 9 Preview 5, introducing significant enhancements to ASP.NET Core. This update focuses on optimizing static web asset delivery and improving the Blazor Server reconnection experience, alongside new features for runtime detection of component render modes and various other improvements to simplify development and enhance user experience.

A major improvement in this release is the optimization of static web asset delivery. The new MapStaticAssets API is designed to replace UseStaticFiles in most cases. MapStaticAssets is optimized for assets known at build and publish time. It compresses assets using gzip and brotli, as stated, reducing their size and improving load times for users.

The API also sets up content-based ETags, ensuring that the browser only downloads files if their content changes. This change simplifies the process for developers, as new libraries or JS/CSS assets are automatically optimized and served faster, which is especially helpful for mobile users with limited bandwidth.

It is stated that even applications that use server-side compression can benefit from MapStaticAssets. With the explanation that the API allows for higher compression ratios because it takes more time during the build process, stating that using brotli compression can reduce the size of the MudBlazor CSS bundle from 90KB to 37KB.

The release also improves the Blazor Server reconnection experience. Blazor Server apps need a real-time connection to function. The new changes introduce an exponential backoff strategy for reconnection attempts, starting quickly and gradually introducing delays.

As stated, if a user returns to an app with a disconnected circuit, the app now tries to reconnect immediately. If the server has released the circuit, an automatic refresh is triggered, removing the need for manual intervention. Additionally, the reconnection UI has been updated to be more user-friendly.

Another new feature is detecting the component render mode at runtime. The ComponentBase class now includes a Platform property, soon to be renamed RendererInfo, with Name and IsInteractive properties. These properties help developers understand where their component runs and whether it is interactive. A new AssignedRenderMode property also provides information on how the component will render after prerendering.

Furthermore, this release has simplified authentication state serialization for Blazor Web Apps. New APIs make it easier to add authentication to existing projects. The development team states the following:

This works well if you've started from the Blazor web app project template and selected the Individual Accounts option, but it's a lot of code to implement yourself or copy if you're trying to add authentication to an existing project.

The new APIs, AddAuthenticationStateSerialization and AddAuthenticationStateDeserialization, simplify this process by adding necessary services to serialize and deserialize the authentication state, enhancing the app's ability to access the authentication state during prerendering.

Additionally, a new .NET MAUI Blazor Hybrid and Web solution template has been introduced. As reported, this template simplifies creating apps that target Android, iOS, Mac, Windows, and Web while maximizing code reuse, and automatically sets up projects for a Blazor Web App and a .NET MAUI Blazor Hybrid app, using a shared Razor Class Library for UI components.

(Template from Visual Studio, Source: Official .NET GitHub)

Lastly, readers can refer to the official documentation for detailed reports on the latest updates. Readers can also review the breaking changes and the roadmap to understand the future direction and for a broader discussion detailed release notes on GitHub can be explored.

About the Author

Rate this Article

Adoption
Style

BT