Blazor Hosting Models
Now that we see what Blazor can do for us, how do we deploy your application out to the public. Blazor has 3 different hosting / configuration formats that can be used.
- Server
- Client
- Client Hosted in Asp.Net Core
Server Hosting
With this hosting model the entire application is ran on the server. Users actions are sent vis SignalR to the server. The server uses a virtual DOM and generates a binary DOM difference file and send it to the client where Blazor applies the changes the Browser. For this hosting model to be most effective, you need to make sure your client will have good connectivity and fast servers. Utilizing Azure, this is easy.
Benefits for Server Hosted
- Works on older browsers
- No business rules on the client
- Small foot print, on client and no API layer
- Built on SignalR
- Easy to Debug
- Gives you full access to the .Net framework
- Downloads and starts fast
Drawbacks for Server Hosted
- Rendering changes is 2-way trips
- Strictly on line
- Lots of client-side connectivity
- Server-less deployment not possible
- Scaling
Client Hosting Model
In the full client hosted model, the entire application is downloaded and ran with in the browser. This is accomplished with the use of Web Assembly. Web Assembly is a web standard that has been around for 3 years. All the green field browsers have been supporting it for a while.
Your application will download a WASM version of the Mono runtime, then execute your application DLLs in that run time.
Since your application runs with in the browser it is bound by the browser sandbox.
Benefits for Server Hosted
- All processing on the client
- Allows offline mode
- Allows serverless deployments, such as CDN
- DOM updates locally (Less chatty)
- IE 11 not supported
Drawbacks for Server Hosted
- Requires Web Assembly
- Larger Downloads
- Debug tools not as mature
- IE 11 not supported
- Limited to Browser capability
Hosting in a CDN
One very cool thing about the Client hosted solution is that it can be deployed via a CDN. This is cheaper and easier to maintain solution than having to update a server. To deploy your client app out to an CDN, follow these steps:
- 1. Create your client Blazor application.
- 2. Log in to your Azure portal
- 3. Create a new storage account
- 4. Once the account is created, go to the Overview => Static Web Site
- 5. Turn static web sites on
- 6. Go to your Blazor Application and publish to a folder
- 7. Upload the publish files, dist folder to your blob storage
- a. You can use the CLI
- b. I prefer to use VS Code with the Azure storage extension.
- 8. Browse out to your new web site
- 9. Put a CDN in front of the web site
- a. Go to the storage overview and select CDN
- b. Click new
- i. Please note that it may take a few minutes for the new web site to get propagated though out the CDN
Client Asp.Net Core Hosting
This hosting type is a mixture of the first 2 models. It is using the client-side web assembly, but it has an API layer that will allow you to do server-side processing when needed. This model matches the normal JavaScript built web application. With this model you can run your sensitive processes on the server while taking advantage of the client-side processing.
Summary
So what is the best way to host your Blazor application? Answer: depends.
As with most decisions in this profession, the choice of hosting depends on your application and use case. If you except low users, non-high data, server side makes sense. If you have high user count, you will need to scale so client might be better. You will need to do some analysis on your application and figure out the best solution.
Comments
Post a Comment