diff --git a/src/ext/sse.js b/src/ext/sse.js index 75c875a17..dcba333f8 100644 --- a/src/ext/sse.js +++ b/src/ext/sse.js @@ -135,6 +135,13 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions var source = htmx.createEventSource(sseURL); internalData.sseEventSource = source; + // Don't forget to disconnect the EventSource on page unload + window.addEventListener("beforeunload", function () { + if (source != undefined) { + source.close(); + } + }); + // Create event handlers source.onerror = function (err) {