4 ms·
I’ve been using Hotwire (turbo and stimulus) with my latest elixir/Phoenix project and it’s been great. Adding dynamic behaviour to pages is quick and easy usi
by agd 6y ago
I’ve been using Hotwire (turbo and stimulus) with my latest elixir/Phoenix project and it’s been great.
Adding dynamic behaviour to pages is quick and easy using the existing templating system. The stateless nature of it helps avoid bugs.
If you really need a very complex / dynamic UX then this isn’t the way to go, but for everything else, I think it’s much simpler than react etc.
- yumraj 6y agoWhy not just use Liveview since you're using Phoenix? Could you share your thoughts on the difference between Liveview and Hotwire.
- agd 6y agoLiveview is stateful and uses websockets (or long polling) whereas turbo is stateless and uses regular http requests. NB. I haven’t used liveview, however turbo seems much simpler on a conceptual level because of the lack of state. This comes with extra performance cost, but on my current project I’m optimising for dev productivity and simplicity.
- yumraj 6y agoI'd be interested in the "how" if you'd consider creating a blog on using Hotwire with Phoenix. Or, if the source is in a public repo.
- nickjj 6y ago> I'd be interested in the "how" if you'd consider creating a blog on using Hotwire with Phoenix. Technically it doesn't involve adding or changing even 1 line of code on the back-end to make Turbo Drive and Frames work with any tech stack. It works out of the box by following Turbo's docs and using the HTML tags they mention along with bringing in the Turbo JS library. But for Frames you can optionally do what Rails does and add some server side code that says "hey, if this request is coming from a Turbo Frame only send the partial template as a response instead of the whole layout". That logic for Rails is here: https://github.com/hotwired/turbo-rails/blob/main/app/controllers/turbo/frames/frame_request.rb https://github.com/hotwired/turbo-rails/blob/main/app/contro.... It's a nice to have optimization that will reduce your frame's HTML payload size but it still works without doing this. It can be ported to Phoenix or any back-end language by using a plug / middleware to not render the layout if a specific header exists in the request. The ETag stuff could be ported over too if your web framework's web server sets an ETag header. Streams are a bit more tricky to get working in other tech stacks since it may involve Websockets. Hopefully we start to see more examples in the future. But I believe it should be possible to pull off in a production ready way with any back-end language that has a good library or built in support for Websockets at the framework level. That means Flask, Django, Laravel and Phoenix are all good to go in this regard (probably others too but I'm not familiar enough with their ecosystems to say for sure).
- bdcravens 6y agoTurbo does use Websockets. "...stream partial page updates over WebSocket" https://hotwire.dev/ https://hotwire.dev/