HTMX Engine Server
TsgcHTMX_Engine_Server — handles htmx partial-page swap requests over HTTP and broadcasts live out-of-band fragments to all connected browsers over WebSocket.
TsgcHTMX_Engine_Server — handles htmx partial-page swap requests over HTTP and broadcasts live out-of-band fragments to all connected browsers over WebSocket.
Bridges htmx's HTTP-driven partial updates with WebSocket server-push. Incoming htmx requests are dispatched to OnHTMXRequest; your handler returns only the fragment to swap in. Call BroadcastFragment at any time to push live out-of-band updates to every connected browser.
TsgcHTMX_Engine_Server
htmx swaps + live server push
Delphi, C++ Builder, .NET
Wire the engine to your WebSocket server, handle partial-swap requests in OnHTMXRequest, and call BroadcastFragment to push updates to every connected browser.
uses
sgcHTMX_Engine_Server;
var
oHTMX: TsgcHTMX_Engine_Server;
begin
oHTMX := TsgcHTMX_Engine_Server.Create(nil);
oHTMX.Server := WSSServer;
oHTMX.OnHTMXRequest := HandleHTMXRequest;
// later, from any thread, push a KPI update:
oHTMX.BroadcastFragment(
'<div id="kpi-revenue" hx-swap-oob="true">' +
CurrToStr(FRevenue) + '</div>');
end;
TsgcHTMX_Engine_Server *oHTMX = new TsgcHTMX_Engine_Server(NULL);
oHTMX->Server = WSSServer;
oHTMX->OnHTMXRequest = HandleHTMXRequest;
// push a live update:
oHTMX->BroadcastFragment(
"<div id=\"kpi-revenue\" hx-swap-oob=\"true\">" +
CurrToStr(FRevenue) + "</div>");
var htmx = new TsgcHTMX_Engine_Server();
htmx.Server = wssServer;
htmx.OnHTMXRequest += HandleHTMXRequest;
// push a live update:
htmx.BroadcastFragment(
"<div id=\"kpi-revenue\" hx-swap-oob=\"true\">" +
revenue.ToString("N0") + "</div>");
The members you reach for most often.
The TsgcWSHTTPServer this engine attaches to; handles both HTTP partial-swap requests and WebSocket push.
Event fired for every htmx-triggered HTTP request; your handler returns just the fragment HTML to swap in.
Sends an out-of-band htmx payload to every currently connected WebSocket client simultaneously.
Called by the host server for each request; identifies htmx headers and routes to OnHTMXRequest or falls through.
htmx's out-of-band swap attribute: the fragment id must match the target element id on the page.
BroadcastFragment is thread-safe; call it from background timers, push threads or event handlers without locking.
| Online HelpFull API reference and usage guide for this component. | Open | |
| All sgcHTML ComponentsBrowse the full feature matrix of 60+ components. | Open | |
| Download Free TrialThe 30-day trial ships the 60.HTML demo projects. | Open | |
| PricingSingle, Team and Site licenses with full source code. | Open |