← All examples

Live SSE

One server-sent-events connection pushes a new price every 2 seconds. The same message also updates an out-of-band ticker, so two regions change from one response.

event: price Connecting…
$0.00
Waiting for the stream…

Restart the demo server to watch EventSource reconnect automatically.

The server message

event: price
data: <span class="price-tag">$42.00</span>
      <div id="ticker" minu-oob="#ticker">tick 21 · 12:00:01 PM</div>

How it works

  1. minu-sse="/events" opens a native EventSource on init.
  2. minu-sse-event="price" filters for the named event, not the default message.
  3. Each message’s data is sanitized and swapped into #price.
  4. The OOB ticker is applied first, then the main span is inserted.
  5. EventSource reconnects on its own; retry: and id: work as usual.
  6. The close button calls minu.closeStream(element).
<div minu-sse="/events"
     minu-sse-event="price"
     minu-target="#price"></div>

<script>
    minu.init();
    // close one stream:
    minu.closeStream(document.querySelector('[minu-sse]'));
</script>

For chat, send with a normal minu-post and receive over SSE. WebSocket is intentionally not included.