But first we need to talk about server-sent events (SSE).

Every request in Datastar is an event stream.

Server-sent events are unidirectional streams and are part of the HTTP standard.

They are lightweight, easy to set up (requiring just a few header declarations) and easy to extend.


event: event-type
id: first-event
retry: 1000
data: some data

The event and id lines are optional.

The retry specifies how long to wait before reconnections in the advent of a connection loss.

Each part of the event is separated by a new line.

A second new line terminates the event.

Since it’s standard HTTP, you can proxy HTTP1 to HTTP2, add compression, etc. with any standard HTTP proxy.

Datastar’s implementation was originally based on Azure’s fetch-event-source implementation.