admin管理员组文章数量:1356468
I'm using React + axios to talk to the API from the client side. I'm a newbie in JavaScript.
How would I implement long polling so I get near real-time updates on a web page?
Is there a better way to do real-time updates on the page, when backend is a JSON REST API? Should I look into using WebSockets or server side events or long polling is fine?
I'm using React + axios to talk to the API from the client side. I'm a newbie in JavaScript.
How would I implement long polling so I get near real-time updates on a web page?
Is there a better way to do real-time updates on the page, when backend is a JSON REST API? Should I look into using WebSockets or server side events or long polling is fine?
Share Improve this question edited Jun 26, 2018 at 13:54 user7637745 9852 gold badges14 silver badges27 bronze badges asked Apr 17, 2017 at 1:11 MaklausMaklaus 6882 gold badges18 silver badges42 bronze badges 2- 6 Related answers: Long-polling vs websocket and Ajax vs Socket.io. For regular real-time updates to a web page, I know of no situation where polling is more efficient than a continuous webSocket or socket.io connection. – jfriend00 Commented Apr 17, 2017 at 1:20
- The question in your title and the question you ask at the end are different. Could you please update the post with a single question so someone can attempt to answer the right question. – Tom Commented Feb 15, 2019 at 10:42
1 Answer
Reset to default 2There is another, potentially better way for your use-case: Server-Sent Events.
SSE, in a nutshell, is a simple GET request to the server from the client - except that the server doesn't close the connection after it's done processing the request. Instead, the HTTP connection is left open and the server is able to write data multiple times to the client, which appear in real-time.
For more info on how SSE pares to Websockets, read Alex Recarey's answer to "WebSockets vs. Server-Sent events/EventSource" in SO.
本文标签: javascriptHow to implement long polling for ReactaxiosStack Overflow
版权声明:本文标题:javascript - How to implement long polling for React + axios - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744010325a2575445.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论