One socket for all liveviews and api routes etc?

I’v been searching around the forum through old posts but can’t find a straight answer.

Can one client websocket connection hit different liveviews, api routes etc from the same connection? Or is it a new connection everytime?

I know new tabs will make new connections.

Generally, a connection is created when a user visits and that connection is maintained for the lifetime of their visit within a live session. It is not used for API calls AFAIK, as they’re plain old boring HTTP requests.

See these two pages of the docs which explain the lifecycle and different types of navigation and their affect on the connection.

https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#content

https://hexdocs.pm/phoenix_live_view/live-navigation.html

3 Likes

Here is blog post on sharing same live session:

1 Like