Search code examples
javascripthttpcometreal-timelong-polling

Short-polling vs Long-polling for real time web applications?


I'm building a real-time web application As far as I know, the most popular choices are short-polling and long-polling. What are the advantages and disadvantages might there be for measuring one over the other?


Solution

    • Short polling (a.k.a. AJAX based timer):

      Pros: simpler, not server consuming (if the time between requests is long).
      Cons: bad if you need to be notified WHEN the server event happens with no delay. Example (ItsNat based)

    • Long polling (a.k.a. Comet based on XHR)

      Pros: you are notified WHEN the server event happens with no delay. Cons: more complex and more server resources used. Example (ItsNat based)