The .NET 11 preview introduces a new `webworker` project template that makes it easier to run CPU-intensive code in Blazor WASM without blocking the UI thread. The post walks through creating a Web Worker project, referencing it from a Blazor app, defining methods with `[JSExport]`, and invoking them asynchronously. It also covers caching the worker instance to avoid repeated .NET runtime startup costs, and dives into the internals of the two JavaScript files (`dotnet-web-worker-client.js` and `dotnet-web-worker.js`) that handle worker creation, message passing, and .NET runtime initialization inside the worker.
Table of contents
Why do you need Web Workers?Adding the Web Worker projectLooking at the Web Worker codeSummarySort: