Support for chunked transfer encoding
carlos-verdes opened this issue ยท 10 comments
Hi, I have a server that is responding with a http chunked response to load data as it's available (also it reduces the consumption of memory on the server):
https://en.wikipedia.org/wiki/Chunked_transfer_encoding
When I make a direct call with my browser I can see how the results pop-up as they are flushed from the server (as expected) however if I use hx-get
I don't see anything in the screen until the full response is sent (not the expected behavior)
I see there is support for SSE and Web Sockets, is there a plan to support this feature also?
This doesn't answer your question, but have you considered using the newer Streams API instead of chunked transfer encoding?
https://developer.mozilla.org/en-US/docs/Web/API/Streams_API
You might also consider using a service worker to fix this problem more immediately than htmx might get around to it - it'll intercept all network requests and you could deal with it as needed (as well as do LOTS more)
I use that API to read from the server when doing SPA development, that's why I'm asking if HTMX will support this feature or not
The good thing about it is you don't need to change the protocol and most of HTTP and actually HTMX just works, the only problem is behavior is not as expected (HTMX waits for full response to be sent before rendering anything back to the user)
I really need this feature (http streaming).
It would be lovely to see this supported
+1
Example use case: Streaming search results. Instead of complex "infinite scroll" or other types of convoluted result delivery schemes, we could just start pushing results to the client as soon as we get first hits from the database - client could start loading and rendering images etc for the first entries in listing right away. Ohh, it would be so straightforward and beautiful, so old school in the bestest of ways.
I send all collections from my backend using streams to avoid also memory pressure on big collections so for me is a natural thing to do
Had to close the above PR but I think the existing extension mechanism should be more than sufficient to implement this. Would love if someone wanted to take that on.
@alexpetros I'm on it ;)
Are you doing extension for this @douglasduteil ?
Can you share link to the PR when ready?
๐ https://github.com/douglasduteil/htmx.ext...chunked-transfer ๐
\to @carlos-verdes it's christmas time again ๐
Install
$ npm install htmx.ext...chunked-transfer
<script src="https://unpkg.com/htmx.ext...chunked-transfer/dist/index.js"></script>
Usage
<body hx-ext="chunked-transfer">
...
</body>