One thing to consider is whether you want/need the user interface to show the changes real time .
(要考虑的一件事是是否要/需要用户界面实时显示更改。)
If showing your data is very time sensitive you probably want to consider a bi-directional protocol like websockets and receive the server updates through this channel.
(如果显示数据对时间非常敏感,则您可能需要考虑使用双向协议(例如websockets)并通过此通道接收服务器更新。)
Another way to mimic a near real-time UI update is to do polling .
(模拟近乎实时的UI更新的另一种方法是进行轮询 。)
The UI (on certain conditions) sets up a schedule to do periodic polling through HTTP using traditional APIs. (UI(在特定条件下)设置时间表以使用传统API通过HTTP进行定期轮询。)
Polling can be a good option if the data requested can be served quickly (not an expensive computation and the amount of transferred data is small) and it does not require to re-render the entire client side of the application. (如果可以快速提供所请求的数据(不是昂贵的计算,并且传输的数据量很小),并且不需要重新渲染应用程序的整个客户端,则轮询可能是一个不错的选择。)
Polling tends to be a bandaid solution and implemented as an afterthought therefore feel extremely heavy handed (lots of data transferred and re-rendering the UIs) but if you plan on light polling it could be a good option. (轮询通常是一个临时的解决方案,并且是事后才想到的,因此感觉非常费力(传输大量数据并重新呈现UI),但是如果计划进行轻度轮询,那么这将是一个不错的选择。)
If you foresee more 'real-time' like aspects of your app, you may want to introduce websockets.
(如果您预见到应用程序的更多“实时”方面,则可能需要引入网络套接字。)
Be cautious on what this means to your architecture and scaling though. (不过,请谨慎使用这对您的体系结构和扩展意味着什么。)
(There are certain architectural styles, eg microservices architectures, where using websockets may introduce more complexity). ((有某些架构样式,例如微服务架构,使用websocket可能会带来更多的复杂性)。)
Browser compatibility may also be a small concern so i'd make sure you are not planning to support browsers that do not support websockets. (浏览器兼容性也可能是一个小问题,因此我将确保您不打算支持不支持websocket的浏览器。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…