3 ms·
You can do whatever you want with them. For example, let's say you push /api/todos and your client-side code does a `fetch('/api/todos')`. This stream stays ope
by Touche 9y ago
You can do whatever you want with them. For example, let's say you push /api/todos and your client-side code does a `fetch('/api/todos')`. This stream stays open, and the client code can receive each message as they come in, using ReadableStream.
Now the server, having this connection open can later push more data into this /api/todos stream. Boom, you have websockets. Without needing a separate port and connection.
- manigandham 9y agoYou just described long-polling: holding the connection open until the response arrives or it times out. Even if you just send push-promises and push-responses while keeping the original response stalled (and the browser accepts the response), the client-side JS still has no idea what those requests were or what was loaded. SSE is the evolution of long-polling so that browsers already include the logic to keep a connection open with streaming updates so that you can avoid all this in the first place.
- Touche 9y agoThis differs from long polling in that http2 doesn't create a new connection. Also long-polling is request and then response, whereas http2 is (like websockets) full duplex.