Channels across pages

Hello there,
what is the best practice for using channels when navigating across pages in a phoenix application?
If channel connection code is put in a layout template, the channel connection is initiated on every page load. Is there a significant performance penalty? Would it be better to implement a single page app style (possibly turbo links), in order to keep a constant connection. I don’t want to use something that is not universally well supported (like web works). Would just like to know how things are done in the Phoenix world. Any help appreciated, thanks.


If you’re not doing a single-page app, there isn’t really an alternative to re-initiating the socket after each page load.
I think the answer to your question really depends on your use-case: If you want to build something that will eventually have offline-capabilities, a SPA seems like the way to go (if you want to avoid using workers). If you are building an application that always requires an internet connection, re-opening the socket shouldn’t be too much of an overhead.


Eh, I’ve been using unpoly.js (I hope that is the right url) to swap the pages bodies without restarting connections and such, it makes it ‘feel’ a lot faster (plus significantly less network requests), just need to use the same layout for the <head/> on all your pages, which I do, so it works wonderfully.

So no SPA, very little javascript, just decorate tags well enough so things stay connected properly, but its almost SPA speed, just server-driven (combined with the Elixir Drab library it really is server-driven).


whoa! nice one