html – WebSocket: can one connection be used for the whole site?

Question:

After establishing a WebSocket connection on the main page of the site, is it possible to continue using the same connection on all other pages? Or should each page initiate its own connection? For some reason, all examples of using WebSocket are limited to only one html file. Please clarify this point.

Answer:

No. The connection is dropped when you leave the page (even if to another page on the same site). So each page must re-initiate the connection.

Scroll to Top