wshaddix/dotnet-skills/dotnet-aot-wasm
Claude Code and agent skill by wshaddix/dotnet-skills
- community
Checking that the SKILL.md file is still in the repository.
AOT-compiling for WebAssembly. Blazor/Uno WASM AOT, size vs speed, lazy loading, Brotli.
Install
npx vskill@latest install wshaddix/dotnet-skills/dotnet-aot-wasmSKILL.md
dotnet-aot-wasm
WebAssembly AOT compilation for Blazor WASM and Uno WASM applications: compilation pipeline, download size vs runtime speed tradeoffs, trimming interplay, lazy loading assemblies, and Brotli pre-compression for download optimization.
Version assumptions: .NET 8.0+ baseline. Blazor WASM AOT shipped in .NET 6 and has been refined through .NET 8-10. Uno WASM uses a similar compilation pipeline with Uno-specific tooling.
Important tradeoff: Trimming and AOT have opposite effects on WASM artifact size. Trimming reduces download size by removing unused code. AOT increases artifact size (native WASM code is larger than IL) but improves runtime execution speed. Use both together for the best balance.
Out of scope: Native AOT for server-side .NET -- see [skill:dotnet-native-aot]. AOT-first design patterns -- see [skill:dotnet-aot-architecture]. Trim-safe library authoring -- see [skill:dotnet-trimming]. MAUI-specific AOT -- see [skill:dotnet-maui-aot]. Blazor component patterns and architecture -- see [skill:dotnet-blazor-patterns] (soft). Uno Platform architecture -- see [skill:dotnet-uno-platform] (soft).
Cross-references: [skill:dotnet-native-aot] for general AOT pipeline, [skill:dotnet-trimming] for trimming annotations, [skill:dotnet-aot-architecture] for AOT-safe design patterns, [skill:dotnet-serialization] for AOT-safe serialization, [skill:dotnet-csharp-source-generators] for source gen as AOT enabler, [skill:dotnet-blazor-patterns] for Blazor architecture (soft), [skill:dotnet-uno-platform] for Uno Platform patterns (soft).
Download Size vs Runtime Speed
Understanding the size/speed tradeoff is critical for WASM AOT decisions:
| Compilation Mode | Download Size | Runtime Speed | Startup Time | |
|---|---|---|---|---|
| IL interpreter (no AOT) | Smallest | Slowest | Fastest startup | |
| AOT (all assemblies) | Largest | Fastest | Slower startup | |
| AOT (selective) + trimming | Balanced | Good | Moderate | |
| Trimmed only (no AOT) | Small | Moderate (JIT interpretation) | Fast |
Key insight: Trimming reduces size by removing unused IL. AOT increases total artifact size because compiled native WASM code is larger than the equivalent IL bytecode. However, AOT-compiled code executes significantly faster because it skips IL interpretation at runtime.
When to Use WASM AOT
- CPU-intensive workloads: Image processing, complex calculations, data transformation
- Predictable performance: Consistent execution speed without JIT pauses
- Hot paths: AOT-compile only performance-critical assemblies (selective AOT)
When to Skip WASM AOT
- Bandwidth-constrained users: AOT increases download size significantly
- Simple CRUD apps: IL interpretation is fast enough for UI interactions and API calls
- Rapid iteration: AOT compilation adds significant publish time
Blazor WASM AOT
Enabling AOT
Note: RunAOTCompilation is the Blazor WASM property (not PublishAot which is for server-side Native AOT). AOT compilation only happens during dotnet publish, not during dotnet run or dotnet build.
Selective AOT via Lazy Loading
Blazor WASM AOT compiles all non-lazy-loaded assemblies. To control which assemblies are AOT-compiled, mark non-critical assemblies as lazy-loaded -- they will use IL interpretation instead:
Trimming + AOT Together
For the best balance, use both trimming and AOT:
The publish pipeline runs: trim unused IL first, then AOT-compile the remaining assemblies to native WASM. This produces an artifact that is larger than trimmed-only but smaller than AOT-without-trimming, with the best runtime performance.
Uno WASM AOT
Uno Platform 5+ with .NET 8+ uses the standard .NET WASM workload, so the AOT configuration is the same as Blazor WASM.
Enabling AOT (Uno 5+ / .NET 8+)
Older Uno versions using Uno.Wasm.Bootstrap had a separate WasmShellMonoRuntimeExecutionMode property with Interpreter, InterpreterAndAOT, and FullAOT modes. On .NET 8+, use RunAOTCompilation instead.
Trimming in Uno WASM
See [skill:dotnet-uno-platform] for Uno Platform architecture patterns.
Lazy Loading Assemblies
Lazy loading defers downloading assemblies until they are needed, reducing initial download size. This is especially effective when combined with AOT (which increases per-assembly size).
Blazor WASM Lazy Loading
Router-Based Lazy Loading
Lazy Loading Strategy
| Strategy | Initial Load | Feature Load | Best For | |
|---|---|---|---|---|
| No lazy loading | All at once | Instant | Small apps (<5 MB total) | |
| Route-based lazy loading | Core only | On navigation | Multi-module apps | |
| Feature-based lazy loading | Core only | On demand | Apps with optional features |
Brotli Pre-Compression
Brotli pre-compression reduces WASM download size by 60-80%. Blazor WASM automatically generates Brotli-compressed files during publish.
How It Works
During dotnet publish, Blazor WASM generates .br (Brotli) and .gz (gzip) compressed versions of all static files in _framework/. The web server serves the pre-compressed file when the browser supports it.
Server Configuration
The web server must be configured to serve pre-compressed files. Most Blazor hosting setups handle this automatically.
ASP.NET Core hosting:
Nginx:
Azure Static Web Apps / GitHub Pages:
Pre-compressed .br files are served automatically when the Accept-Encoding: br header is present.
Compression Impact
| Content | Original | Brotli (.br) | Reduction | |
|---|---|---|---|---|
| .NET WASM runtime | ~2.5 MB | ~0.8 MB | ~68% | |
| App assemblies (IL) | varies | ~70% smaller | ~70% | |
| App assemblies (AOT) | varies | ~65% smaller | ~65% | |
| JavaScript glue code | ~100 KB | ~25 KB | ~75% |
Disabling Compression (Rarely Needed)
WASM Size Optimization Checklist
- Enable trimming -- removes unused IL before AOT compilation
- Use lazy loading -- defer non-critical assemblies
- Enable Brotli pre-compression -- 60-80% reduction in transfer size (on by default)
- Use selective AOT -- only AOT-compile performance-critical assemblies
- Enable invariant globalization if culture-specific formatting is not needed:
``xml <PropertyGroup> <InvariantGlobalization>true</InvariantGlobalization> </PropertyGroup> ``
- Remove unused framework features:
``xml <PropertyGroup> <!-- Disable features you don't use --> <EventSourceSupport>false</EventSourceSupport> <HttpActivityPropagationSupport>false</HttpActivityPropagationSupport> </PropertyGroup> ``
- Verify compression is served -- check browser DevTools Network tab for
content-encoding: br
Agent Gotchas
- Do not confuse `RunAOTCompilation` with `PublishAot`. Blazor WASM uses
RunAOTCompilationfor WASM AOT.PublishAotis for server-side Native AOT and produces a different kind of binary. - Do not assume AOT reduces WASM download size. AOT increases artifact size because native WASM code is larger than IL bytecode. Use trimming to reduce size and AOT to improve runtime speed.
- Do not forget to publish when testing AOT. WASM AOT only runs during
dotnet publish, notdotnet run. Debug builds always use IL interpretation. - Do not lazy-load assemblies that are needed at startup. Only lazy-load assemblies for features accessed after initial navigation. Loading a lazy assembly triggers a network request.
- Do not skip Brotli compression verification. Ensure your web server serves
.brfiles. Without compression, WASM downloads are 3-5x larger than necessary. Check browser DevTools forcontent-encoding: brheader. - Do not AOT-compile all assemblies when download size matters. Use
BlazorWebAssemblyLazyLoadto defer non-critical assemblies -- lazy-loaded assemblies use IL interpretation instead of AOT.
References
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/dotnet-aot-wasm/SKILL.md
Popularity
- Repository stars
- 1
- 7-day trend score
- 3
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 18 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/wshaddix/dotnet-skills/dotnet-aot-wasm)