EXPERIMENTAL hx-ws

The hx-ws allows you to work with Web Sockets directly from HTML. The value of the attribute can be one or more of the following, separated by commas:

Here is an example:

  <div hx-ws="connect wss:/chatroom">
    <div id="chat_room">
      ...
    </div>
    <form hx-ws="send">
        <input name="chat_message">
    </form>
  </div>

This example establishes a WebSocket to the chatroom end point. Content that is send down from the websocket will be parsed as HTML and swapped in by the id property, using the same logic as Out of Band Swaps.

The form uses the send syntax to indicate that when it is submitted, the form values should be serialized as JSON and send to the nearest enclosing WebSocket.

The serialized values will include a field, HEADERS, that includes the headers normally submitted with an htmx request.

Notes