Blazor.LightMode
0.1.0
See the version list below for details.
dotnet add package Blazor.LightMode --version 0.1.0
NuGet\Install-Package Blazor.LightMode -Version 0.1.0
<PackageReference Include="Blazor.LightMode" Version="0.1.0" />
paket add Blazor.LightMode --version 0.1.0
#r "nuget: Blazor.LightMode, 0.1.0"
// Install Blazor.LightMode as a Cake Addin #addin nuget:?package=Blazor.LightMode&version=0.1.0 // Install Blazor.LightMode as a Cake Tool #tool nuget:?package=Blazor.LightMode&version=0.1.0
Blazor LightMode 🎉
Create Blazor Server applications without persistent WebSocket connections.
Blazor LightMode is a library that allows you to build Blazor Server applications without the need for persistent WebSocket connections. By eliminating the dependency on SignalR and WebSockets, you can simplify deployment, improve scalability, and operate in environments where WebSockets are not supported.
Why Blazor LightMode? 🤔
Blazor Server apps traditionally use SignalR and WebSockets to maintain real-time communication between the client and the server. While this enables powerful interactive features, it also introduces complexity and requires persistent connections, which can be a challenge in certain hosting environments.
Blazor LightMode addresses this by:
- Simplifying Networking Requirements: Operate over standard HTTP without the need for WebSocket support.
- Reducing Server Load: Eliminate the overhead of maintaining numerous persistent connections.
- Improving Compatibility: Deploy your Blazor Server apps in environments where WebSockets are restricted or unavailable.
How It Works 🔧
Blazor LightMode replaces the traditional duplex communication model with a client-initiated request-response pattern:
- Client Requests: The client sends a request to the server whenever it needs data or an update.
- Server Responses: The server processes the request and returns the required data along with a flag indicating if more data is available.
- Polling Mechanism: If more data is available, the client continues to send requests until all updates are received.
This approach ensures that all communication is initiated by the client, effectively removing the need for persistent connections and server-initiated communication.
Pros and Cons ⚖️
Pros ✅
- Simplified Deployment: No need to configure or support WebSocket connections on your server or in your network infrastructure.
- Enhanced Scalability: Reduced server resource usage by eliminating the overhead of managing persistent connections.
- Greater Compatibility: Works in environments where WebSockets are blocked or not supported, such as certain corporate networks or older browsers.
Cons ❌
- No Real-Time Server Push: The server cannot push updates to the client without a client request.
- Increased Latency: Data updates may have slight delays due to the polling nature of client requests.
- Less Suitable for Real-Time Applications: Not ideal for applications that require instant updates, such as live chats or real-time dashboards.
Getting Started 🚀
Installation 📦
Install the Blazor.LightMode NuGet package:
dotnet add package Blazor.LightMode
Configuration ⚙️
Update Program.cs
Add the following using directive:
using Blazor.LightMode;
Register Blazor LightMode services:
builder.Services.AddLightMode();
Configure the middleware:
app.UseLightMode();
Remove or comment out the following line if present:
app.AddInteractiveServerRenderMode();
Update App.razor
Replace the existing Blazor script reference:
<script src="_framework/blazor.server.js"></script>
With the Blazor LightMode script:
<script src="_content/Blazor.LightMode/blazor.lightmode.js"></script>
Build Your Application 🚀
You can now build your Blazor Server application as usual. All components and pages will function without persistent WebSocket connections.
Contributing 🤝
Contributions are welcome! If you'd like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Commit your changes with clear messages.
- Open a pull request detailing your changes.
License 📄
This project is licensed under the MIT License.
Acknowledgements 🙏
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Microsoft.AspNetCore.Components (>= 8.0.0)
- Microsoft.AspNetCore.Components.Web (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.