Search⌘ K
AI Features

Improving Blazor WebAssembly

Explore techniques to improve Blazor WebAssembly applications by enabling Ahead-of-Time (AOT) compilation for faster runtime performance despite longer build and download times. Discover how to add Progressive Web App (PWA) support to allow offline use, installability, and native-like features. Learn the installation steps to enable AOT, test PWA functionality, and understand considerations like increased app size and offline behavior.

Enabling Blazor WebAssembly AOT

By default, the .NET runtime used by Blazor WebAssembly is doing IL interpretation using an interpreter in WebAssembly. Unlike other .NET apps, it does not use a just-in-time (JIT) compiler, so the performance of CPU-intensive workloads is lower than we might hope for.

In .NET 6 and later, Microsoft added support for ahead-of-time (AOT) compilation, but we must explicitly opt-in because although it can dramatically improve runtime performance, AOT compilation can take several minutes on small projects and potentially much longer for larger projects. The size of the compiled app is also larger than without AOT, typically twice the size. The decision to use AOT is therefore based on a balance of increased compile and browser download times with potentially much faster runtimes.

AOT was the top requested feature in a Microsoft survey, and the lack of AOT was cited as a primary reason why some developers had not yet adopted .NET for developing single-page applications (SPAs).

Installation of workload for Blazor AOT

...