How does JS interop in a Blazor component hosted within ASP.NET Core differ in performance characteristics between Server and WebAssembly render modes?
Short answer
In Blazor Server, every IJSRuntime.InvokeAsync call is a real network round-trip over the SignalR connection between browser and server, adding latency proportional to network conditions -- making frequent, chatty JS interop calls a potential bottleneck.
Advertisement
AModel answer
In Blazor Server, every IJSRuntime.InvokeAsync call is a real network round-trip over the SignalR connection between browser and server, adding latency proportional to network conditions -- making frequent, chatty JS interop calls a potential bottleneck. In Blazor WebAssembly, JS interop happens entirely in-process within the browser (WASM calling into JS directly), making it dramatically faster since there's no network hop involved, though still not free due to WASM-to-JS marshaling overhead.
// Identical code, very different performance characteristics depending on render mode:
await JS.InvokeVoidAsync("updateChart", chartData);
// Blazor Server: network round-trip over SignalR
// Blazor WebAssembly: in-process, no network latencyReal-world example
A Blazor Server app calling JS interop on every mouse-move event for a drawing feature experiences noticeable lag due to round-trip overhead, prompting the team to switch that specific interactive component to WebAssembly render mode instead.
Likely follow-ups
- How would you batch multiple JS interop calls to reduce round-trip overhead in Blazor Server?
- What is Interactive Auto mode's trade-off regarding this performance difference?
Related topics