W3cubDocs

/DOM

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 + data inside the web page.

Concepts and usage

To learn how to use server-sent events, see our article Using server-sent events.

Interfaces

EventSource
Defines all the features that handle connecting to a server, receiving events/data, errors, closing a connection, etc.

Examples

Specification

Browser compatibilityUpdate compatibility data on GitHub

EventSource interface

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 6 No 6 No Yes 5
Available in workers Yes No 53 No Yes Yes
EventSource() constructor 9 No 6 No 11 5
close 6 No 6 No Yes 5
onerror 6 No 6 No Yes 5
onmessage 6 No 6 No Yes 5
onopen 6 No 6 No Yes 5
readyState 6 No 6 No Yes 5
url 6 No 6 No Yes 5
withCredentials 6 No 6 No Yes 5
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support Yes 18 No 45 12 5 ?
Available in workers Yes Yes No 53 Yes Yes ?
EventSource() constructor Yes 18 No 6 11 5 ?
close Yes 18 No 45 12 5 ?
onerror Yes 18 No 45 12 5 ?
onmessage Yes 18 No 45 12 5 ?
onopen Yes 18 No 45 12 5 ?
readyState Yes 18 No 45 12 5 ?
url Yes 18 No 45 12 5 ?
withCredentials Yes 18 No 45 12 5 ?

See also

Tools

Other resources

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events