DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk4 min

Server-Sent Events Explained: How SSE Works and When to Use It

Server-Sent Events stream updates from a server to browser JavaScript over HTTP. Learn the event format, reconnection behavior, and deployment trade-offs.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Server-Sent Events (SSE) let a browser receive a continuous stream of updates from a server over HTTP. JavaScript connects with the native EventSource API; the server sends UTF-8 text formatted as events. SSE is a good fit when updates mainly travel from server to browser and the client can send its own actions through ordinary HTTP requests.

How Server-Sent Events work

A browser opens an EventSource connection to a URL. The server responds with an HTTP event stream and keeps the response open while it sends updates. The browser parses the stream and dispatches an event whenever it reaches a blank line.

As an Amazon Associate I earn from qualifying purchases.

The response uses the text/event-stream media type, and the stream must be UTF-8. Its fields are plain text lines; a blank line marks the end of an event.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Connect from browser JavaScript

const source = new EventSource("/events");
source.onmessage = (event) => {
  console.log(event.data);
};
source.addEventListener("status", (event) => {
  console.log("status", event.data);
});

Events without a custom name are delivered as message events, handled above by onmessage. To receive an event with a custom name, register a listener for that name.

Send a correctly framed event

The server should return Content-Type: text/event-stream and write each event with a blank line after its fields. For example:

event: status
data: {"state":"ready"}

The browser parses the fields and dispatches the named status event with the JSON text in event.data. The application still needs to parse that text as JSON if it wants to use it as an object.

Rank #2
Forvencer Server Book, 2 Zipper Pocket, Server Books for Waitress
  • Upgraded Two Zipper Pockets: Forvencer server books feature two secure zipper pockets for better organization of coins, cash, and receipts, ensuring that everything you collect has a safe and secure place
  • Smart Storage & Quick Access: Designed with 8 multi-functional compartments, the right side includes a guest receipt pad, while the left has a money pocket, ticket pocket, and credit card slot. Two small clear pockets store bills, receipts, and other visible items. A stitched pen loop ensures you always have your favorite pen ready
  • High-quality & Easy to Clean: Crafted from high-quality PU leather with heavy-duty stitching, this server book is built to last. It resists tears, scratches, and its waterproof surface makes cleaning easy with just a damp cloth or a non-chlorine sanitizer
  • Perfect Fit for Your Apron: Measuring 5” x 8”, this compact organizer is slightly smaller than other models, making it ideal for bending or sitting while carrying in your server apron. It holds everything a waitress needs—a place for everything
  • What's Included: This server organizer comes with multiple open and zippered pockets to store money, receipts, tips, etc. Clear sleeves are perfect for keeping menus or special lists while serving. Available in a variety of colors, allowing you to express yourself even when in uniform

What the SSE fields mean

Field Purpose
data Contains the event payload. Multiple data: lines are supported and are combined for the event.
event Sets a custom event name. Without it, the event name is message.
id Sets the event’s last-event ID, which the browser can use when reconnecting.
retry Specifies a reconnection delay in milliseconds.

A line beginning with a colon is a comment rather than an event field. The browser ignores it, so servers can use comment lines as keep-alives without triggering application listeners.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Reconnection is not message storage or guaranteed replay

When an SSE connection ends, the browser’s EventSource normally tries to reconnect. A server can send a retry: field to suggest the delay, and an id: field to update the last-event ID. On a later connection, the browser can send that ID so the server can identify the position the client last received.

That mechanism does not store events, guarantee that missed events will be replayed, or deduplicate messages. The application must maintain any event history it needs and decide what to send after a reconnect. It also needs an approach to duplicate or out-of-order updates if those matter. The standard defines HTTP 204 as a signal for the client to stop reconnecting.

Close the stream when it is no longer needed, for example when the page leaves the view or the user signs out:

source.close();

When SSE is a sensible choice

SSE suits applications that mostly push updates from a server to a browser, while client actions can travel separately through regular HTTP requests. Examples include a dashboard receiving refreshed status, a page showing job progress, notifications, or incremental generated output. These are application patterns, not special SSE features.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Before choosing, compare the actual traffic and deployment requirements:

  • Direction: SSE delivers server-to-client events. If the application needs frequent, ongoing messages in both directions, compare a WebSocket-based design.
  • Client request control: Native EventSource is convenient, but its constructor accepts a URL and a withCredentials option; it does not define arbitrary request headers or a request body. If the client must customize requests in those ways, check whether the API fits.
  • Recovery: Reconnection and last-event IDs provide useful protocol hooks, not durable history or application-level delivery guarantees. Decide how the server will handle missed events and duplicates.
  • Payload: SSE frames UTF-8 text in named fields. Confirm that text payloads suit the data and encoding needs of the application.
  • Operations: Check server resource use, proxy and load-balancer timeouts or buffering, and browser connection behavior for the HTTP versions in use.

Neither SSE nor WebSockets is universally faster, cheaper, or more scalable. The relevant trade-offs depend on the workload and deployment.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Deployment details that affect reliability

Keep idle connections alive

Some older intermediaries close connections they consider idle. The HTML Standard suggests that a server send a comment line roughly every 15 seconds to protect against certain short-timeout intermediaries. This is guidance for those conditions, not a universal keep-alive interval guarantee. See the WHATWG HTML Standard’s Server-sent events section.

Flush the stream through every layer

Each event needs to reach the browser promptly. A server, reverse proxy, or CDN that buffers output can delay updates; chunking performed by a layer that does not account for the stream’s timing can also affect reliability. Verify flushing and buffering behavior across the actual deployment path rather than checking only the application code.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Account for connection concurrency

With HTTP/1.1, multiple tabs opening streams to the same server can run into browser per-server connection limits. MDN describes a low limit of six in that context. Under HTTP/2, the client and server negotiate the maximum concurrent streams; MDN reports a default of 100. These figures describe browser and protocol context, not a guarantee for every client or server. Check the browsers and HTTP configuration your application supports. See MDN’s guide to using server-sent events.

Check browser support and authentication constraints

The WHATWG standard’s compatibility summary lists support across current browser engines but not Internet Explorer. Confirm support against the browser versions your users need. For authentication, the standard provides the withCredentials option, but not arbitrary header configuration; account for that constraint when selecting an authentication approach.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.