htmx/www/attributes/hx-sse.md
2020-06-11 17:24:35 +02:00

1.0 KiB

layout title
layout.njk </> htmx - hx-sse

EXPERIMENTAL hx-sse

The hx-sse allows you to work with Server Sent Event EventSources directly from HTML. The value of the attribute is of the following form:

  • connect <url> - A URL to establish an EventSource against

When a connection for server sent events has been established, child elements can listen for these events by using the special hx-trigger syntax sse:<event_name>. This, when combined with an hx-get or similar will trigger the element to make a request.

Here is an example:

  <div hx-sse="connect /event_stream">
    <div hx-get="/chatroom" hx-trigger="sse:chatter">
      ...
    </div>
  </div>

This example establishes an SSE connection to the event_stream end point which then triggers a GET to the /chatroom url whenever the chatter event is seen.

Notes

  • hx-sse is not inherited