Search code examples
javascriptpusherpusher-js

Why Pusher keep making POST requests each seconds?


I'm using Pusher websocket and i would like to understand why it keeps making POST requests every 10-20 seconds:

app.js:66006 XHR finished loading: POST "https://sock26-us2.pusher.com/pusher/app.......

After some time my console log this:

(699) XHR finished loading: POST "<URL>".

699 POST Requests, it just never stop making POST requests, is this normal? Because i don't see it happening in other sites that use websockets.


Solution

  • Sometimes network conditions (firewalls, connection instability etc) can make it difficult to maintain a websocket connection. To help in this scenario the Pusher-js library has a number of automatic fallbacks to long polling / streaming to help you maintain a reliable connection in these conditions. This is why you are seeing a lot of POST requests.

    The library will first try to connect via websockets and if this fails or there are lots of disconnections it will automatically retry using another transport mechanism.

    The library will also cache the best transport mechanism for a period of time and will prefer a fallback. Once the cache expires it will retry via websockets if your network conditions have improved.

    You can see more details of websocket fallbacks here:

    https://pusher.com/docs/channels/using_channels/websocket-fallbacks