Loading...
HTTP/1.1 200 OK
Content-Type: application/json
{"msg": "hi"}HTTP/1.1 200 OK
Content-Type: text/event-stream
Cache-Control: no-cache
id: 1
data: {"msg": "hi"}
SSE needs the 'text/event-stream' type and data: lines ending with a blank line; id: lets the browser resume after reconnecting.
Content-Type: text/event-stream and Cache-Control: no-cache.id so reconnects resume with Last-Event-ID.EventSource is closed with close() when the component unmounts.No, EventSource cannot set custom headers. Use cookies, or read the stream with fetch and parse events yourself.
Over HTTP/1.1 browsers allow about six connections per domain across all tabs. HTTP/2 and later multiplex streams, so the limit rarely matters.
The browser sends the last received id in the Last-Event-ID header, so the server can replay missed events.