Server-sent events
Server Sent Events
Server Sent Events
Traditionally, a web page has to send a request to the server to receive new data; that is, the page requests data from the server. With server-sent events, it's possible for a server to send new data to a web page at any time, by pushing messages to the web page. These incoming messages can be treated as _[Events](/docs/Web/API/Event) + data_ inside the web page.
## Concepts and usage
To learn how to use server-sent events, see our article [Using server-sent events](/docs/Web/API/Server-sent_events/Using_server-sent_events).
## Interfaces
- EventSource
- : Defines all the features that handle connecting to a server, receiving events/data, errors, closing a connection, etc.
## Libraries
- [Mercure: a real-time communication protocol (publish-subscribe) built on top of SSE](https://mercure.rocks/)
- [Transmit: a native opinionated Server-Sent-Event (SSE) module built for AdonisJS](https://docs.adonisjs.com/guides/digging-deeper/server-sent-events)
- [EventSource polyfill for Node.js](https://github.com/EventSource/eventsource)
- intercooler.js [declarative SSE support](https://intercoolerjs.org/docs.html#sse)
## Examples
- [Simple SSE demo using PHP](https://github.com/mdn/dom-examples/tree/main/server-sent-events)
## Specifications
## See also
- [Learn: Making network requests with JavaScript](/docs/Learn_web_development/Core/Scripting/Network_requests)
- [JavaScript](/docs/Web/JavaScript)
- [WebSockets](/docs/Web/API/WebSockets_API)
- [Creating a wall/feed social application](https://hacks.mozilla.org/2011/06/a-wall-powered-by-eventsource-and-server-sent-events/) powered by server-sent events and [its code on GitHub](https://github.com/mozilla/webowonder-demos/tree/master/demos/friends%20timeline).
Cite this
"Server-sent events". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy