Elixir vs Stimulus: Hotwire and LiveView Compared
Rails and Phoenix teams ended up in a similar place from different directions. Both got tired of shipping JSON to a big JavaScript app, and both went back to sending HTML from the server. Rails did it with Hotwire, which became the default for new Rails apps in Rails 7. Phoenix did it with LiveView.
Stimulus is one half of Hotwire. So when someone searches "elixir vs stimulus", I think the real question is: I know Hotwire, how does LiveView compare, and do I still need Stimulus in Phoenix?
What Stimulus does
Stimulus calls itself "a modest JavaScript framework for the HTML you already have". You write small controllers in JavaScript and attach them to HTML with data attributes: a dropdown, a copy button, a character counter. The server renders the page, Stimulus adds behaviour on top.
The other half, Turbo, swaps in HTML from the server so pages update without full reloads. Hotwire's pitch is sending "HTML instead of JSON over the wire".
What LiveView does differently
LiveView goes one step further. The page keeps a persistent connection to the server, and the state of the page lives on the server as Elixir data. When the state changes, because the user clicked or because something happened elsewhere, LiveView sends only the changed parts of the HTML.
In Hotwire terms, it's as if Turbo Streams were always on and the server remembered every open page. That's what makes live dashboards, collaborative screens and chat cheap to build. Doing that per page for thousands of users is a load the BEAM handles well, with one lightweight process per connection.
Do you need Stimulus in Phoenix?
Mostly no. The things you'd write a Stimulus controller for have built-in answers in LiveView:
- Show, hide, toggle classes, transitions, focus: JS commands run in the browser without a server round trip.
-
Anything that needs real JavaScript (a chart library, a map, a rich text editor): a hook, attached with
phx-hook, which plays the same role as a Stimulus controller. - Form validation, search as you type, live updates: plain LiveView events, written in Elixir.
You could load Stimulus into a Phoenix app, it's just JavaScript. I don't see a reason to. You'd have two ways to do the same thing.
What carries over from Rails
If you're a Rails team, the mental model transfers well. Server renders HTML, JavaScript is for small behaviours, no SPA. The difference is where the state lives: in Hotwire most of it lives in the HTML and the database, in LiveView it lives in a process on the server for as long as the page is open.
That changes a few habits. You think about what the process holds in memory, and you get real-time updates almost for free. I compared the two ecosystems in more depth in Elixir vs Rails.
Hotwire and LiveView next to each other
| Hotwire (Turbo + Stimulus) | Phoenix LiveView | |
| Language | Ruby on the server, JS controllers | Elixir, small JS only when needed |
| Where page state lives | HTML and database | Server process per page |
| Connection | Requests, websockets for streams | Persistent websocket |
| Client behaviour | Stimulus controllers | JS commands and hooks |
| Real-time updates | Turbo Streams | Built in |
Thinking about moving?
If your Rails app is happy on Hotwire, there's no urgent reason to move. If the real-time parts or the server bill are where it hurts, have a look at how we migrate module by module, with the Rails app running the whole time.