Replace constant stat polling with server-sent events
At the moment webui is constantly polling following HTTP API endpoints:
This is has few unfortunate consequences:
- Increases pressure on network IO limits that browsers have.
- Inceases overhead on the HTTP API of IPFS node (draining battery).
- Harms dev experience due to noise in the network panel.
Describe the solution you'd like
EventSource is a standard web API that provides interface to server-sent-events as replacement for ong-polling pattern (that browsers can optimize to discard consumed input).
Describe alternatives you've considered
Alternatively we could use fetch body to read updates from ReadableStream, but that is less widely supported than EventSource API. Also unlike EventSource that is push based, ReadableStreams are push & pull which could lead to buffering on the client if not actively consumed, which would not be the case with EventSource.
Additional context I am realizing this conversation reaches beyond webui into IPFS HTTP API, but I'm going to fill relevant issues there as well and interlink those.
Another solution would be to have websockets handle these kinds of updates. I know that involves a higher number of changes, but I believe it's the most efficient approach to this.
@rafaelramalho19 the problem with Websockets is that when used from a Secure Context (https or localhost IP) they require the other end to also be a Secure Context, making it impossible to use API over LAN IP without setting up TLS. EventSource does not have that limitation and may be easier to add, as it does not require opening any new ports or creating new APIs.
@Gozala I agree its worth exploring. This would not only benefit WebUI, but also Desktop and Companion. I converted existing https://github.com/ipfs/in-web-browsers/issues/140 to an epic – feel free to update its description and link relevant issues to it.