Although it works great with Rails, you don't really have to use Rails (or Ruby) to get most of the benefits of Hotwire. Most static websites can just drop-in the Turbo library to behave like responsive single-page applications, without incurring any of the costs and complexities associated with the SPA frameworks.
If you have an existing app written in PHP, Go, Rust, or even Java, you can start using Hotwire, right now. All you have to do is follow certain conventions.
This lesson is divided into two parts:
Learn how you can use the first two Hotwire techniques (Turbo Drive and Turbo Frames) in a simple static website, to fetch and update entire web pages or parts of the page, without fully-reloading the browser. We'll use a simple static site to demo this.
Learn how to tweak your existing back-end code to send Turbo Streams to update multiple parts on your website dynamically, in response to form submissions. Since Turbo Streams work with form submissions, I'll use Sinatra to demo this.
For those of you who don't enjoy reading long, rambling posts that try to explain every nook and cranny of the topic at hand, I've uploaded the finished project on my GitHub account, which also contains the instructions to get started. Just clone the repository, run
npm run launch
, and you're good to go.