Blazor Server vs. Blazor WebAssembly 裝載模型

ASP.NET Core Blazor 裝載模型(hosting models) 比較。

參考原文

請參考原文,關於 ASP.NET Core Blazor 裝載模型比較,它寫得很清楚。

官方說明文件,沒講到使用者想知道的重點。

Blazor WASM App v.s. Blazor Server App

Blazor WASM App v.s. Blazor Server App

重點比較節錄

Blazor Server vs. Blazor WebAssembly Features

Before, I go into the details of each version of Blazor, let’s have a look at their features.

§ WebAssembly Hosting Model

  • WASM runs in the browser on the client.

  • The first request to the WASM application downloads the CLR, Assemblies, JavaScript, CSS (React and Angular work similar).

  • It runs in the secure WASM sandbox.

  • The Blazor Javascript handler accesses the DOM (Document Object Model).

Advantages

  • Faster UI Code

  • When performance matters use WASM

  • Offline support

  • Can be distributed via CDN, no server required (except for API)

  • Any .Net standard 2.0 C# can be run

Disadvantages

  • An API layer is required if you want to access secure resources

  • Debugging still a bit limited

§ Server Hosting Model

  • The C# code runs on the server.

  • Javascript hooks are used to access the DOM.

  • Binary messages are used to pass information between the browser and the server using SignalR.

  • If something is changed the server sends back DOM update messages.

Advantages

  • Faster loading than WASM

  • Access to secure resources like databases or cloud-based services

  • Supports browsers which don’t support WASM like IE 11

  • C# code is not sent to the browser

Disadvantages

  • Extra latency due to sending data back and forth

  • No offline support

  • Scalability can be challenging

  • Server required (serverless possible)

Conclusion

Blazor Server and WebAssembly application both have their advantages and disadvantages. If you want to serve a large number of users and don’t have secret code running, use WASM. It also offers offline support. Use Blazor Server if you need fast loading of the first page or if you have sensitive code that you don’t want to send to the browser.

本人再結論一次

Server Hosting Model

WebAssembly Hosting Model

通訊方法

SignalR / binary message

HTTP 封包

通訊安全性

天生較高

需加工 bearer token, anti-forgery token 等等

前端引擎

無 WASM,C# code 不會送到前端

有 WASM ,速度較快且可跑 C# code

前端UI

已有第三方元件 MudBlazor 等支援

已有第三方元件 MudBlazor 等支援

與後端通訊

撰寫 Service,SignalR 自動同步

需要 Web API 通訊自己控制

Scalability

較多工夫

較方便

框架特徵

有 WebForm 運作特徵『前後端塑合』

似 React CSR App框架

適合應用

安全性較高的應用

眾多使用者、安全性較低要求的應用

EOF

Last updated