
Long polling is implemented on the back of XMLHttpRequest, which is near-universally supported by devices so there’s usually little need to support further fallback layers.READ MORE: Learn how WebSockets work A WebSocket connection is a thin layer built on top of TCP/IP Long polling: pros and cons Long polling advantages

It is an as-close-to-raw-as-possible TCP communication layer, although it adds a few abstractions to eliminate certain friction and cater to the fact that the web has additional security considerations that must be taken into account to protect both consumers and service providers. An overview of WebSocketsĪ WebSocket connection is a thin transport layer built on top of a device’s TCP/IP stack. HTTP long polling leaves an HTTP connection open so that the server can continue to deliver response data. To avoid this effort, in long polling, the server elects to hold a client connection open for as long as possible, and delivers a response when new data becomes available or if a timeout threshold is reached. For example, establishing a new connection, parsing the HTTP headers, a query for new data, response generation and delivery, and finally connection closure and clean up. Long polling takes HTTP request/response polling and makes it more efficient, since repeated requests to a server wastes resources. In this article, we compare WebSockets and long polling. Instead you need a push-based method like WebSockets, long polling, server-sent events (SSE) or HTTP2 push. The usual AJAX request/response doesn’t keep the connection open for this sort of use case.


To build a live experience for users online, your service will need to retrieve information as soon as it’s available.
