SSE
Frontend half of SSE (there is also backend part)
Properties: SSE Frontend Pieces
HTMX SSE extension in base.html:
<script src="{% static 'js/htmx.sse.js' %}" defer></script>Template:
<div hx-ext="sse" sse-connect="{% url 'my_app:book_updates' %}"> <div> <span sse-swap="message">Waiting for server...</span> </div> </div>
Properties: SSE Use Cases
Real-time table (
hx-trigger="sse:<message-name>")Status indicator (
sse-swap)
Definition: sse-swap
Put the sse result text into the tag.
Definition: hx-trigger="sse:<message-name>"
Trigger tag’s request whenever new sse result appears.
Workflow: How to add SSE to UI?
Determine if type of sse is
sse-swaporhx-trigger="sse:<>".sse-swapMake sure view returns correct text.
Put it on element and have it swapped
hx-trigger="sse:<>"Make sure you got
hx-getor similar on that tagAdd the trigger to the element: hx-trigger=”sse:your-message-name”.
Ensure the backend sends an event with the matching name.