Blazor
C# used here to write UI code.
Blazor runs C# code directly in the browser using WebAssembly. We can run any type
of code in the browser using WebAssembly.
HOSTING MODEL:
A hosting model defines how your application is hosted, configured, and served to
handle incoming HTTP requests. They determine the relationship between the ASP.NET
Core application and the web server, influencing factors such as performance,
scalability, and deployment flexibility.
Blazor Hosting Model: Blazor WebAssembly and Blazor Server.
1. Blazor WebAssembly:
• Runs entirely in the browser using WebAssembly (code that runs directly in
the browser. Supports languages like C, C++ and C#.
• Pros:
- UI updates are handled directly in the browser (no server interaction
needed) and wors offline after the first load.
- Can be hosted as static files like CDN, Github pages etc.
• Cons:
- Uses browser resources more, as processing happens in the browser.
- Longer initial load time.
• Best Use Cases:
- Progressive web apps (apps available to user in any browser, like google
sheets, online shopping app)
- Client heavy apps (dashboards, games).
2. Blazor Server:
• Runs the app on server and uses SignalR (WebSocket) to update the UI in
real time.
• Pros:
- UI is rendered on server and only UI updates are sent using SignalR.
- No .NET runtime is downloaded to the browser.
- Fast initial load time because client does not need to download
everything.
- App logic stays on the server (more secure).
• Cons:
- Requires constant server connection.
- Increases server load.
- Higher latency compared to WebAssembly.
• Best use cases:
- Internal business apps.
- Apps requiring real-time updates.
Q) Which is better Blazor WebAssembly or Blazor Server?
A) It depends on the use case. Blazor WebAssembly is better for offline apps, client-
heavy apps, and PWAs where performance and reducing server dependency are key.
Blazor Server is better for real-time, data-driven applications that require security and
fast initial load times.
COMPONENT-DRIVEN FRAMEWORK:
ASP .NET Core Blazor is a component driven framework, i.e. components are the basic
building blocks of the Blazor application.
These components can be nested, reused and can also be shared across multiple
applications. Component files have the extension .razor.