What is hotwire with RoR?
Randy Steele
Posted on April 24, 2021
Introduction
Earlier this year the creator of Ruby on Rails, David Heinemeier Hansson (aka DHH) spoke at a conference in Chicago and discussed a new framework he helped to created called "Hotwire". DHH stated that Hotwire is "an alternative approach to building modern web applications without using much JavaScript." Hotwire is described as "HTML over-the-wire" therefore it generates HTML instead of JSON and delivers it to the server.
Why Use Hotwire
I've been researching Hotwire lately and I asked myself this question: "Why use Hotwire instead of JavaScript or a JavaScript framework or library?" This is what I have determined.
- It's a great option for full-stack development. I don't think it's any secret that a lot of programmers were using Rails as a backend only for an application. I think with the release of Hotwire, DHH is attempting to make Ruby on Rails once again, more relevant for full-stack web development.
- Hotwire comes with something called Turbo. Turbo uses complementary techniques to dramatically reduce the amount of custom JavaScript that most web applications will need to write. Turbo makes links and forms submissions quicker by removing the need for full page reloads.
- While Turbo handles at least 80% of the interactivity that would typically be handled by JavaScript, you may find yourself in a situation where you need a small amount of JavaScript code, in that case, Stimulus is available. Stimulus uses an HTML-centric approach to state and wiring.
So, how do I get Hotwire?
The first step I'd recommend is going to Hotwire For Rails On Github
Installation:
- Add `hotwire-rails gem to your Gemfile.
- Run
bundle install
- Run `hotwire:install Hotwire also has the following resources available: Hotwired Turbo Rails Hotwired Stimulus-rails
Final Thoughts
I think Hotwire is a good option for programmers that's don't necessarily love working with JavaScript. I think the folks that think Rails is "too slow" and "can't scale" may give Hotwire a shot and see what they think of it. I also like the fact that you can use a tiny bit of JavaScript when needed by way of Stimulus.
Have you used Hotwire with Rails? Let me know what you think!
Posted on April 24, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.