If you are getting started with Rails it makes sense to read first:
- https://guides.rubyonrails.org/
- https://brdn.design/articles/good-resources-to-learn-ruby-rails-in-2022
Let’s get acquainted with Rails Hotwire.
Hotwire
https://hotwired.dev/
Hotwire is an approach to building web apps without using much JavaScript by sending HTML instead of JSON over the wire. Simply said, it allows you to create “monolith” single-page web application with Ruby / PHP / whatever on the back and (little) JS on the front (no React, Redux, Formik, etc).
Hotwire highlights:
- Speeds up application (cause it prevents the whole page from reloading when you follow a link or submit a form).
- Reduces the amount of JavaScript we need.
- Simplify adding real-time features (https://turbo.hotwired.dev/handbook/streams).
- Hotwire Turbo provides the tooling to wrap your web app in a native iOS / Android shell (https://turbo.hotwired.dev/handbook/native).
- Pairs nicely with Rails thanks to https://github.com/hotwired/turbo-rails & https://github.com/hotwired/stimulus-rails.
It became possible with:
- the browser support for ES6 / ESM https://caniuse.com/?search=ecmascript%20module,
- WebSockets https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API,
- Web Components https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements
- HTTP/2,
- import maps https://github.com/WICG/import-maps, https://github.com/rails/importmap-rails.
Hotwire consists of 3 technologies:
- Turbo https://turbo.hotwired.dev/, https://turbo.hotwired.dev/handbook/introduction, https://github.com/hotwired/turbo-rails
- Stimulus https://stimulus.hotwired.dev/, https://stimulus.hotwired.dev/handbook/introduction, https://github.com/hotwired/stimulus-rails
- Strada will premiere in 2022
Hotwire is the default front-end framework since Rails 7 (released on December 15, 2021).
Before Hotwire there was https://github.com/defunkt/jquery-pjax. It would asynchronysly fetch fragments of HTML from the server and updated the dom.