Blazor Client Side (WASM) or Server Side #31
Replies: 13 comments
-
I agree that a WASM target is a good thing for a few reasons (It is a "Blazor" strong point, SPAs are getting so popular/useful, etc) However, at the moment I think that WASM is hard to debug. And having the both Server and WASM options for as long as possible is nice... Blazor train shows how to develop both Server and WASM simultaneously, And this article also does a great job discussing it! (I think he makes all of his examples support both) |
Beta Was this translation helpful? Give feedback.
-
The ability to build the application then host it in different ways does seem to be one of Blazor's unique strengths at this point, so it could make make sense to go down the 'both' route. I guess the only caveat there would be if it ends up costing more effort (to maintain this hybrid approach) than the benefit of having that flexibility. The hybrid approach generally works without too much overhead but occasionally you end up having to implement things twice, simply because WASM/Server behave differently. Perhaps an initial spike is in order (testing out the approach, using the resources mentioned by @harperjohn). |
Beta Was this translation helpful? Give feedback.
-
Thanks @harperjohn and @jonhilt. Certainly one for us to ponder over in the coming days and I must re-watch that Blazor Train episode. |
Beta Was this translation helpful? Give feedback.
-
It seems that MudBlazor easily supports both Server and WASM... And if you go to https://mudblazor.com/ you can see a button in the upper right corner that allows for the dynamic switching between Server and WASM Note - If you download the Mudblazor source - There is a "server" project in the solution that is the MudBlazor website! So you can run it locally and we can see how they built their "dual" app. |
Beta Was this translation helpful? Give feedback.
-
What a world we live in when you can just clone a software repository and be able to see such great code. That's what they'll say about TimeKeeper one day! 😃 I see they have amongst others the below projects
You won't believe I worked this out so quickly however MudBlazor.Docs.Client is the WASM project, MudBlazor.Docs.Server is the server side project and MudBlazor.Docs is the project that is shared between Docs.Client and Docs.Server. MudBlazor.Docs contains all the pages and components In MainLayout.razor I note the below code.
In MainLayout.razor.cs I note the below code.
As Larry David would say pretty, pretty, pretty, pretty, pretty, good! |
Beta Was this translation helpful? Give feedback.
-
Overall I think we are edging towards an agreement to at least try and provide a hybrid Client and Server application. If for whatever reason it starts to become too onerous we will drop back to only Client in the first instance. One thing we do need to be aware of is that having a server side version will impact the Azure hosting options. See issue #12 however as I type this I realise that could actually be another advantage as we'll gain experience of hosting both a client and server Blazor application in Azure. |
Beta Was this translation helpful? Give feedback.
-
I realise now when I said "as we'll gain experience of hosting both a client and server Blazor application in Azure." that's not correct as in terms of hosting it will be a single combined app rather than separate client and server Blazor apps. One of the advantages of client Blazor apps is that you can host as a static site which I think in Azure means you can choose a cheaper option but I don't think we need to worry about that too much in our scenario. |
Beta Was this translation helpful? Give feedback.
-
Yes it feels like thee general situations: Blazor Server - Needs a "constant" server connection. Period. |
Beta Was this translation helpful? Give feedback.
-
If we do go down the dual hosting scenario, it might be worth building a WebAPI layer directly in the server soluition so that we can share:
This should reduce the maintenance overhead going forward (it will still be greater with 2 hosting models) |
Beta Was this translation helpful? Give feedback.
-
Agreed. If we're going to have a Blazor WASM frontend then the only way it can really interact with the backend is via Web API. As it is, this doesn't need to be too complicated to set up. Here's one example I put together (primarily for demonstrating prerendering but it's the same basic architecture). https://github.com/jonhilt/blazor-wasm-net5-example The Server project exposes an API controller (in this case for the weather sample demo thingy). The WASM UI then makes an HTTP call to this endpoint to fetch data: Whereas the Blazor Server part of the project can just bypass the controller and fetch the data more directly: If that makes sense. |
Beta Was this translation helpful? Give feedback.
-
Perfect! Only thing we'll need to add is authentication and authorization (which I went through on another project today). Unfortunately I can't share the GitHub code (Enterprise project), however I might add documentation as it had a few tricks. |
Beta Was this translation helpful? Give feedback.
-
Sounds good @ripteqdavid :-) |
Beta Was this translation helpful? Give feedback.
-
@ripteqdavid and @jonhilt I agree! And really like the "Server API" for shared/common server processing. As time/experience goes by I am really seeing the benefit of keeping the server/wasm options as synced/interchangeable as possible. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
We need to decide whether to implement the application using Blazor Client Side (WASM) or Server Side.
https://docs.microsoft.com/en-us/aspnet/core/blazor/hosting-models?view=aspnetcore-5.0
Given the below requirement and the potential for a large amount of users I'm leaning towards Blazor Client Side.
Beta Was this translation helpful? Give feedback.
All reactions