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
Hypertext Markup Language (HTML) is the standard markup language for documents designed to be displayed in a web browser. It defines the content and structure of web content. It is often assisted by technologies such as Cascading Style Sheets ...
by the
WHATWG
The Web Hypertext Application Technology Working Group (WHATWG) is a community of people interested in evolving HTML and related technologies. The WHATWG was founded by individuals from Apple Inc., the Mozilla Foundation and Opera Software, ...
. The
media type
In information and communications technology, a media type, content type or MIME type is a two-part identifier for file formats and content formats. Their purpose is comparable to filename extensions and uniform type identifiers, in that they ide ...
for SSE is
text/event-stream
.
All modern browsers support server-sent events:
Firefox
Mozilla Firefox, or simply Firefox, is a free and open-source web browser developed by the Mozilla Foundation and its subsidiary, the Mozilla Corporation. It uses the Gecko rendering engine to display web pages, which implements curr ...
6+,
Google Chrome
Google Chrome is a web browser developed by Google. It was first released in 2008 for Microsoft Windows, built with free software components from Apple WebKit and Mozilla Firefox. Versions were later released for Linux, macOS, iOS, iPadOS, an ...
6+,
Opera
Opera is a form of History of theatre#European theatre, Western theatre in which music is a fundamental component and dramatic roles are taken by Singing, singers. Such a "work" (the literal translation of the Italian word "opera") is typically ...
11.5+,
Safari
A safari (; originally ) is an overland journey to observe wildlife, wild animals, especially in East Africa. The so-called big five game, "Big Five" game animals of Africa – lion, African leopard, leopard, rhinoceros, African elephant, elep ...
5+,
Microsoft Edge
Microsoft Edge is a Proprietary Software, proprietary cross-platform software, cross-platform web browser created by Microsoft and based on the Chromium (web browser), Chromium open-source project, superseding Edge Legacy. In Windows 11, Edge ...
79+.
[When can I use... Server-sent DOM events](_blank)
/ref>
As SSE relies on persistent connections and chunked transfer encoding, it needs at least HTTP/1.1. In HTTP/2 the multiplexing on a shared TCP connection can lead to head-of-line blocking
Head-of-line blocking (HOL blocking) in computer networking is a performance-limiting phenomenon that occurs when a queue of packets is held up by the first packet in the queue. This occurs, for example, in input-buffered network switches, out-o ...
.
History
The SSE mechanism was first specified by Ian Hickson as part of the "WHATWG
The Web Hypertext Application Technology Working Group (WHATWG) is a community of people interested in evolving HTML and related technologies. The WHATWG was founded by individuals from Apple Inc., the Mozilla Foundation and Opera Software, ...
Web Applications 1.0" proposal starting in 2004. In September 2006, the Opera web browser implemented the experimental technology in a feature called "Server-Sent Events".[Stream Updates with Server-Sent Events, Eric Bidelman, HTML5Rocks website.](_blank)
/ref>
Example
var source = new EventSource('updates.cgi');
source.onmessage = function (event) ;
See also
* Chunked transfer encoding
*Push technology
Push technology, also known as server Push, refers to a communication method, where the communication is initiated by a server rather than a client. This approach is different from the " pull" method where the communication is initiated by a clien ...
*Comet
A comet is an icy, small Solar System body that warms and begins to release gases when passing close to the Sun, a process called outgassing. This produces an extended, gravitationally unbound atmosphere or Coma (cometary), coma surrounding ...
References
External links
Server-Sent Events
HTML Living Standard.
HTML5 Server-push Technologies, Part 1
Introduction into HTML5 Server-push Technologies. Part 1 covers ServerSent Events.
Using Server-Sent Events
A concise example of how to use server-sent events, on the Mozilla Developer Network.
EventSource reference on MDN
Django push: Using Server-Sent Events and WebSocket with Django
Django push: Using Server-Sent Events and WebSocket with Django.
Server-Sent Events vs WebSockets
HTML5
Internet terminology
Push technology
Web development
{{Internet-stub