1. Server-Sent Events (SSE) & EventSource
The Server-Sent Events (SSE) API enables web servers to push real-time data updates to the client over a persistent, single HTTP connection. Unlike WebSockets, SSE is unidirectional (server-to-client) and features built-in automatic reconnects.
Start the SSE stream listener to receive server-pushed price updates:
2. Real-Time Protocols Comparison (Polling vs WebSockets vs SSE)
Choosing the right real-time communication technique depends on data directionality, firewall friendliness, and network overhead.
Polling vs WebSockets vs Server-Sent Events (SSE) Protocol Comparison
Select a real-time scenario to inspect the ideal protocol architecture:
3. Native HTML5 <dialog> Modal Element (.showModal())
The native <dialog> element replaces custom div-overlay modal hacks with native browser accessibility, focus trapping, and pseudo-element backdrop styling.
| Method / API | Description |
|---|---|
dialog.showModal() |
Opens dialog as a top-layer modal (traps keyboard focus & renders ::backdrop). |
dialog.show() |
Opens dialog as a non-modal overlay (allows interaction with underlying page). |
dialog.close(returnValue) |
Closes dialog and optionally sets the dialog.returnValue string. |
<form method="dialog"> |
Special form method that automatically closes the parent dialog on submission. |
Using Native <dialog> Modal
Click to trigger the native browser modal dialog with ::backdrop blur:
4. Declarative Popover API (popover & popovertarget)
The baseline Popover API provides zero-JavaScript declarative popups, tooltips, and dropdown menus with native light-dismiss (clicking outside closes the popover).
Popover API & Top-Layer Render Stack Architecture
Declarative HTML Popover Syntax
Click the invoker button to trigger a zero-JavaScript popover rendered in the Top-Layer:
Zero-JS popover active! Click anywhere outside to test native light dismissal.
5. HTML5 History API (pushState & replaceState)
The History API powers client-side routing in Single Page Applications (SPAs) by updating the URL in the address bar without triggering full page reloads.
SPA Client-Side Routing with `pushState`
Click routes below to update location hash state without triggering page reloads:
Hands-On Challenge: Build a Real-Time Live Notification Center
Build a real-time notification badge system using EventSource streams that pops open a native <dialog> modal when critical alert payloads arrive.
Chapter 19 Key Takeaways
- Use
EventSourcefor unidirectional server-to-client HTTP streaming with native auto-reconnect. - Use
dialog.showModal()to open accessible modals in the browser's Top-Layer with focus trapping. - Use declarative
popover="auto"andpopovertargetfor zero-JS popups with automatic light-dismiss. - Use
history.pushState()andwindow.onpopstatefor Single Page Application client-side routing.