Media type / text
text/event-stream
Server-Sent Events. A single long-lived response whose body is an open-ended stream of `data:` frames the browser delivers through EventSource.
Served inline: Browsers display this in the tab without granting it script access to the page. Safe to serve inline, provided the bytes really are what the header claims.
Browser behaviour
Renders inertly
Charset
charset required
Compression
Do not compress
Send it like this
Content-Type: text/event-stream; charset=utf-8Send `; charset=utf-8`. Without it the receiver falls back to its own default — for some text types that default is us-ascii, and any non-ASCII character then renders wrong.
Handling verdict
Browsers display this in the tab without granting it script access to the page. Safe to serve inline, provided the bytes really are what the header claims.
Send `; charset=utf-8`. Without it the receiver falls back to its own default — for some text types that default is us-ascii, and any non-ASCII character then renders wrong.
Compression and buffering both hold events until a buffer fills, which stalls a live stream indefinitely. Disable both on this route specifically.
Registered with IANA through a public review process, so the name is stable and every implementation can rely on it meaning the same thing.
Anatomy of the name
RFC 6838Top-level type
text
Text
Subtype
event-stream
Registered in the standards tree.
Structured syntax
none
No suffix, so the payload format is defined entirely by the subtype itself.
Parameters
charset
Beyond the charset rule above, this type defines no parameters of its own.
What trips people up
2 notes- Do not compress or buffer it. A proxy that gzips or chunks this stream holds events until its buffer fills, which looks exactly like a broken server.
- Send `X-Accel-Buffering: no` for nginx and disable proxy buffering, or events arrive in bursts minutes late.
Response headers
Content-Type: text/event-stream; charset=utf-8
X-Content-Type-Options: nosniff
Content-Disposition: inline
Cache-Control: no-cache
Connection: keep-alive
X-Accel-Buffering: nonosniff stops the browser second-guessing the type you declared, which is what makes the rest of this reliable. Serving it inline is safe here because the browser renders it without granting it script access.
Server configuration
route headernginx
# text/event-stream has no file extension — set it on the route instead
add_header Content-Type "text/event-stream; charset=utf-8";Apache
# text/event-stream has no file extension — set it on the handler instead
Header set Content-Type "text/event-stream; charset=utf-8"Caddy
header Content-Type "text/event-stream; charset=utf-8"