When does LiveView use long polling instead of websocket?

Yes, exactly. The fallback was added by default relatively recently, here you find more details:

At 00:00:58 Chris talks about long poll fallback.
(https://www.reddit.com/r/elixir/comments/16mi7qn/comment/k18nhjq/)

The client first tries to connect via WebSocket, and then ping the server to ensure the connection actually works.

If the WS doesn’t work for whatever reason, the client uses the fallback and saves a key to session storage (persistent until the browser is restarted) to go straight to the fallback in future page loads.

The circumstances are many, could be browser support, problems with network proxies messing up with WS messages, etc. Can also happen, many times during development, that the client is trying to connect while the server is down and then eventually sticks to the fallback long poll transport until the session is cleared.

4 Likes