+++ title = "htmx Server Sent Event (SSE) Extension" +++ The `Server Sent Events` extension connects to an [EventSource](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) directly from HTML. It manages the connections to your web server, listens for server events, and then swaps their contents into your htmx webpage in real-time. SSE is a lightweight alternative to WebSockets that works over existing HTTP connections, so it is easy to use through proxy servers and firewalls. Remember, SSE is a uni-directional service, so you cannot send any messages to an SSE server once the connection has been established. If you need bi-directional communication, then you should consider using [WebSockets](@/extensions/ws.md) instead. This extension replaces the experimental `hx-sse` attribute built into previous versions of htmx. For help migrating from older versions, see the migration guide at the bottom of this page. Use the following attributes to configure how SSE connections behave: * `sse-connect=""` - The URL of the SSE server. * `sse-swap=""` - The name of the message to swap into the DOM. * `hx-trigger="sse:"` - SSE messages can also trigger HTTP callbacks using the [`hx-trigger`](https://htmx.org/attributes/hx-trigger) attribute. * `sse-close=` - To close the EventStream gracefully when that message is received. This might be helpful if you want to send information to a client that will eventually stop. ## Installing The fastest way to install `sse` is to load it via a CDN. Remember to always include the core htmx library before the extension and [enable the extension](#usage). ```HTML ``` An unminified version is also available at https://unpkg.com/htmx-ext-sse/dist/sse.js. While the CDN approach is simple, you may want to consider [not using CDNs in production](https://blog.wesleyac.com/posts/why-not-javascript-cdn). The next easiest way to install `sse` is to simply copy it into your project. Download the extension from `https://unpkg.com/htmx-ext-sse`, add it to the appropriate directory in your project and include it where necessary with a `