I am building a small chat application for friends, but unsure about how to get information in a timely manner that is not as manual or as rudimentary as forcing a page refresh.(我正在为朋友构建一个小型聊天应用程序,但是不确定如何及时获取信息,而这不像强制刷新页面那样手动或基本。)
Currently, I am implementing this using simple AJAX, but this has the disadvantage of regularly hitting the server when a short timer elapses.(目前,我正在使用简单的AJAX来实现此功能,但是这样做的缺点是,在经过短计时器后会定期命中服务器。)
In researching long/short polling, I ran across HTML5 WebSockets.(在研究长/短轮询时,我遇到了HTML5 WebSockets。) This seems easy to implement, but I'm not sure if there are some hidden disadvantages.(这似乎很容易实现,但是我不确定是否存在一些隐藏的缺点。) For example, I think WebSockets is only supported by certain browsers.(例如,我认为WebSockets仅受某些浏览器支持。) Are there other disadvantages to WebSockets that I should be aware of?(我应该知道WebSockets还有其他缺点吗?)
Since it seems like both technologies do the same thing, in what sorts of scenarios would one prefer to use one over the other?(既然两种技术似乎都做同样的事情,那么在哪种情况下,一个人宁愿使用另一个?) More specifically, has HTML5 WebSockets made AJAX long/short polling obsolete, or are there compelling reasons to prefer AJAX over WebSockets?(更具体地说,HTML5 WebSockets是否已使AJAX长/短轮询不再适用,还是有充分的理由偏爱AJAX而不是WebSockets?)
ask by somdow translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…