开发者

JS: auto updates without multiple XHRs

I was looking at things like Google realtime search (not google instant) and facebook chat for example. They have data constantly coming up but at unpredictable intervals. However, it always seems to come up almost instantly.

I've implemented something like this at http://malachy.org.uk/stream, however the way I've done it is by having an XHR check for updates every couple of seconds, which I guess is a bit inefficient, and anyway while che开发者_开发百科cking the net requests log in firebug on google realtime for example I don't see XHRs coming up at nearly the rate of new posts (well on trendy topics anyway).

Any idea how this is done?

Cheers


Look at:

  • Reverse AJAX
  • WebSockets

Because HTTP protocol (being used by AJAX) is a typical request/response protocol, there is no easy way to achieve this. Reverse AJAX uses few clever techniques like long-polling whether WebSockets is a brand new technology somewhere around HTML5, addressing this problem completely (yet not well established and implemented).

Your solution (asking the server every few seconds) is the simplest one, but it introduces both high volume of networks calls and sometimes unacceptable latency.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜