how to let channel alive outside a single page?

hi everyone!
I’m working on a mock-up e-commerce and I’d like to implement a live notification system for an item re-stock, but it’s not clear to me how to deal with a creation of a channel for each item opened in the page of the item_detail and then getting the notification in another page without opening a new socket.
in my idea there was to open a connection to a channel room until the user gets a notification but I don’t really understand how to deal with the javascript and the sockets

Welcome @coccmat !

The short answer is that you can’t.

A full page load disposes of all the JavaScript on the current page, and loads the JavaScript defined or referenced on the new page.

You’ll need to reopen the socket on each separate page being loaded, or convert your application to an SPA.

1 Like

thank you @KenWhitesell really appreciate, I guess this is a solution? I thought that could be a solution to implement live notification through my application.

I’m not sure I understand what you’re asking here.

Both of those options are solutions, each with their own implications. Moving to an SPA means (potentially) a lot of rearchitecting of your system. Reopening the websocket creates a window of time between when the old socket is closed and the new socket is opened - time in which messages being sent could be lost. (If it’s necessary to ensure no messages are lost, you’d need to build a message queue and the code to manage it.)

Oh, sorry for the confusion, I meant that the solution was that there’s no way to do what I wanted to initially. I was able to move on from my issue. Thank you again for your input!