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.   

  1. Server 
  2. Client 
  3. 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. 1. Create your client Blazor application. 
  1. 2. Log in to your Azure portal 
  1. 3. Create a new storage account 
  1. 4. Once the account is created, go to the Overview => Static Web Site 
 

  1. 5. Turn static web sites on 
 

  1. 6. Go to your Blazor Application and publish to a folder 
 

  1. 7.  Upload the publish files, dist folder to your blob storage 
  1. a. You can use the CLI 
  1. b. I prefer to use VS Code with the Azure storage extension. 
  1. 8.  Browse out to your new web site 
  1. 9.  Put a CDN in front of the web site 
  1. a. Go to the storage overview and select CDN 
 
  1. b. Click new 
  1. 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

Popular posts from this blog

Yes, Blazor Server can scale!

Blazor - Cool Blur Loading Page

Blazor new and improved Search Box