Home

EventSourcehttpsexamplecomevents

EventSource refers to the technique of Server-Sent Events (SSE) implemented via the EventSource API in web browsers. It enables a client to receive automatic, real-time updates from a server over a single long-lived HTTP connection. It is designed for unidirectional server-to-client communication and complements techniques such as polling and WebSockets.

Communication with SSE uses the HTTP-based text/event-stream format. The server streams events as lines of text.

The transport remains a single open HTTP connection. The server can send events whenever available, and the

Usage and compatibility considerations include browser support, cross-origin access via CORS, and security implications. SSE works

Each
event
can
include
data
lines
prefixed
with
data:,
an
optional
event
type
prefixed
with
event:,
an
optional
identifier
prefixed
with
id:,
and
an
optional
retry
time
prefixed
with
retry:.
An
empty
line
ends
the
current
event.
Data
lines
are
concatenated
to
form
the
event
payload,
and
if
no
event
type
is
specified
the
default
type
is
message.
On
the
client
side,
events
are
delivered
via
an
EventSource
object,
with
handlers
for
onmessage
and
onerror,
and
the
ability
to
listen
for
named
events.
client
attempts
automatic
reconnection
with
a
backoff
strategy
if
the
connection
is
lost,
using
the
retry
value
if
provided.
The
connection
is
typically
established
with
a
GET
request
to
the
stream
URL
and
content
is
delivered
with
the
text/event-stream
MIME
type.
well
for
live
updates
such
as
feeds
or
notifications
and
is
generally
simpler
and
lighter
than
WebSockets
for
server-to-client
streams.
Limitations
include
lack
of
binary
data
support,
no
built-in
full-duplex
communication,
and
reliance
on
HTTP
streaming
semantics.
Standards
are
defined
in
the
WHATWG
HTML
Living
Standard,
with
wide
implementation
in
major
browsers.