Blazor WebAssembly optimizations I missed...
I've been unintentionally skipping something in my CI/CD pipeline for my website that reduces the overall file size. 😬
Due to the nature of how Blazor WASM works, there are some extra files required for a website/web app to work in everyone's web browser. More specifically the .NET runtime converted to WebAssembly. By default, this is the uncompressed size of the file:
One thing to keep in mind is that the file distributed to the web browser is actually compressed with Brotli, so you're not actually downloading
Simple. Make sure the
wasm-tools workload is installed for the
You can install it by running this command:
dotnet workload install wasm-tools
The long answer
wasm-tools adds an extra step when running
dotnet publish with the release config: Runtime relinking. This basically trims the .NET runtime of code that your website/web app does not use.
This was the size of the .NET runtime WebAssembly:
1.39 MB difference!
So I added this step to my build and deploy workflow on GitHub before I run
- name: Install wasm-tools
run: dotnet workload install wasm-tools