A proof of concept htmx extension for streaming contents using http streaming.
Archived now, as I don't really want to improve it much further. But the core principle still works like wonders!
- Copy all contents from index.js
- Paste them into a script after the htmx initialization.
- Profit
On the client:
<form hx-ext="stream" hx-get="/stream">
<button>stream changes</button>
</form>
On the server:
r.GET("/stream", func(c *gin.Context) {
c.Writer.Write([]byte(`
<div>
<h1>First streaming part</h1>
</div>
`))
c.Writer.Flush()
<-time.After(300 * time.Millisecond)
c.Writer.Write([]byte(`
<div>
<h1>Second streaming part</h1>
</div>
`))
c.Writer.Flush()
<-time.After(300 * time.Millisecond)
c.Writer.Write([]byte(`
<form hx-get="http://localhost:8080/">
<h1> final part </h1>
<button>do it again</button>
</form>
`))
c.Writer.Flush()
})
The extension will overwrite the previous contents of the target with the new streamed html.