{{Short description|Server push technology}} '''Server-Sent Events''' ('''SSE''') is a server push technology enabling a client to receive automatic updates from a server via an HTTP connection, and describes how servers can initiate data transmission towards clients once an initial client connection has been established. They are commonly used to send message updates or continuous data streams to a browser client and designed to enhance native, cross-browser streaming through a JavaScript API called EventSource, through which a client requests a particular URL in order to receive an event stream. The EventSource API is standardized as part of HTML Living Standard<ref>{{Cite web |date=31 March 2022 |title=HTML Living Standard: 9.2 Server-sent events |url=https://html.spec.whatwg.org/multipage/server-sent-events.html |publisher=WHATWG}}</ref> by the WHATWG. The media type for SSE is <code>text/event-stream</code>.
All modern browsers support server-sent events: Firefox 6+, Google Chrome 6+, Opera 11.5+, Safari 5+, Microsoft Edge 79+, Brave.<ref name="caniuse.com">[https://caniuse.com/eventsource When can I use... Server-sent DOM events]</ref> Since SSE does not use either persistent connections nor chunked transfer encoding, HTTP/1.1 is not a technical requirement.
== History == The SSE mechanism was first specified by Ian Hickson as part of the "WHATWG Web Applications 1.0" proposal starting in 2004.<ref>{{cite web |editor-last=Hickson |editor-first=Ian |date=2006-01-01 |df=dmy |title=Server-sent DOM events |department=Web Applications 1.0 |url=https://whatwg.org/specs/web-apps/2006-01-01/#scs-server-sent |website=WHATWG |access-date=2024-05-09}}</ref> In September 2006, the Opera web browser implemented the experimental technology in a feature called "Server-Sent Events".<ref>{{cite web |last=Bersvendsen |first=Arve |date=1 September 2006 |title=Event Streaming to Web Browsers |url=http://dev.opera.com/blog/event-streaming-to-web-browsers/ |url-status=dead |archive-url=https://web.archive.org/web/20140704185432/http://dev.opera.com/blog/event-streaming-to-web-browsers/ |archive-date=2014-07-04 |website=dev.opera.com}}</ref><ref name="tutorial">[http://www.html5rocks.com/en/tutorials/eventsource/basics/ Stream Updates with Server-Sent Events, Eric Bidelman, HTML5Rocks website.]</ref>
The W3C published Server-Sent Events as a Recommendation on February 3, 2015, after years of development through Working Drafts and Candidate Recommendations.<ref>{{Cite web |date=2021-01-28 |title=Server-Sent Events publication history |url=https://www.w3.org/standards/history/eventsource/ |access-date=2026-04-14 |website=W3C |language=en}}</ref>
== Example == <syntaxhighlight lang="javascript"> var source = new EventSource('updates.cgi'); source.onmessage = function (event) { alert(event.data); }; </syntaxhighlight>
== Technology == When sending high-frequency data , the server must manage backpressure to prevent saturating clients.<ref name=":0">{{Cite news |last=Mohamed-Ali |date=2025-03-11 |title=Server-Sent Events: A Comprehensive Guide |url=https://medium.com/@moali314/server-sent-events-a-comprehensive-guide-e4b15d147576 |archive-url=http://web.archive.org/web/20250624061622/https://medium.com/@moali314/server-sent-events-a-comprehensive-guide-e4b15d147576 |archive-date=2025-06-24 |access-date=2026-04-14 |work=Medium |language=en}}</ref> This is mitigated in the following ways:
* Client-side buffering: Browsers have limited buffer space for incoming server-sent events<ref name=":0" /> * Adaptive rate limiting: Servers can adjust event frequency and monitor connection health * Event batching: Combining multiple events into larger and less frequent transmissions
==See also== {{Portal|Internet}} *Chunked transfer encoding *Push technology * WebSocket * Client–server model *Comet
==References== <references/>
==External links== *[https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events Server-Sent Events]. HTML Living Standard. *[https://community.oracle.com/docs/DOC-982924 HTML5 Server-push Technologies, Part 1]. Introduction into HTML5 Server-push Technologies. Part 1 covers ServerSent Events. *[https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events Using Server-Sent Events]. A concise example of how to use server-sent events, on the Mozilla Developer Network. *[https://developer.mozilla.org/en-US/docs/Web/API/EventSource EventSource reference on MDN] *[https://web.archive.org/web/20121115183325/http://curella.org/blog/django-push-using-server-sent-events-and-websocket/ Django push: Using Server-Sent Events and WebSocket with Django] Django push: Using Server-Sent Events and WebSocket with Django. *[https://apifriends.com/api-streaming/server-sent-events/ Server-Sent Events vs WebSockets] {{Web interfaces}}
{{DEFAULTSORT:Server-sent events}} Category:HTML5 Category:Internet terminology Category:Push technology Category:Web development {{Internet-stub}}