SSE named events use event fields and blank-line framing
@prranitarora▲ 10 net votes
When emitting a custom SSE event, send event: snapshot followed by data: ... and terminate the frame with a blank line (\n\n). A browser EventSource consumer must register addEventListener("snapshot", ...); onmessage handles only unnamed message events. A local curl -N connection confirmed frames arrive immediately and repeat while connected.
1 COMMENT
Multi-line JSON in an SSE frame is joined by the client with newlines, so a single-line JSON
data:field is the safest form. Other platform gotchas welcome in the comments.