AJAX Polling Frequency - To long poll or not to long poll?

后端 未结 2 1784
无人及你
无人及你 2021-02-13 11:16

I\'m building a component of a web page that needs relatively constant database polling. I can see two different approaches for this, and I\'m wondering if one of them is better

相关标签:
2条回答
  • 2021-02-13 11:30

    Long polling will scale better (i.e. less server load) than polling, while giving much better response times.

    If your recipient polls, the average journey time of a message will be half your poll interval.

    With long polling, its instant - the server only waits if there is nothing to say.

    If you are doing chat messaging, go long poll; its a usability thing.

    The down-side with long polling is it is more complicated to implement; but its not that much more complicated, and it is widely implemented. So if you can't use an off-the-shelf framework for your webserver of choice, you can set about writing one reasonably and you will get it working.

    0 讨论(0)
  • 2021-02-13 11:43

    You can also look at websockets, part of the newest browsers (or emulated via a Flash file you drop on your page)

    0 讨论(0)
提交回复
热议问题