Hotwire/Turbo on Rails saves your money

Here I will demonstrate how you will save more than 50% of you budget using Hotwire instead of JS libraries like React. Having all cool aspects of a smooth modern App.

SPA is acronym for Single Page Application. These are applications which doesn’t reload full page, but only parts of the page giving to the user a smoother feeling, and not losing focus in page. This opens the door to create Mobile Native Apps based on these libraries (like React Native).

Main problem of these SPA modern applications (with React, Vue, Angular…) is that they increase a lot the complexity of web applications by needing a JSON API server and Frontend application, triplicating your systems and human resources.

Rails solves this smartly by sending its traditional HTML partials to be replaced in the browser by Turbo.js, based on the HTML tag information. So you are saving on complexity, development costs and number of developers. And promoting happiness for your developer!!!

Hotwire is divided in two packages Stimulus and Turbo. At the same time Turbo is divided in Drive, Frames and Streams:

  • Stimulus allows you to join the manipulation of HTML views, DOM and third party libraries by creating Controllers. This allows to maintain a better modularized and cleaner Javascript code.
  • Turbo Drive solves the turbolinks approach by replacing the HTML body with the response of GET or POST calls to the server, instead of reloading full page. Giving to Rails views SPA-feeling without any development cost. Also manages gratefully the browser cache problem in SPA applications.
  • Turbo Frames goes a step further by replacing page fragments. The clue here is to generate html partials in server, and replace these in view.
  • Turbo Streams goes further by using ActionCable to use Websockets, creating a live-feeling in your app by broadcasting html partials to different users when info is changed in server.

As you see the key feature is that you are getting HTML from backend, and replacing it directly in frontend. So you don’t need a specific API server, you only need your traditional Rails server. And no need of a huge Javascript Application (heavily implemented with React, Vue,….), so you don’t have to triplicate development costs to have a SPA-feeling app.

Solving this part, you can also use Turbo to create Mobile Native Apps with turbo-android and turbo-ios.

Leave a Reply

Your email address will not be published. Required fields are marked *