Hotwire

To gain a clearer understanding and a broader perspective on Hotwire Native, let’s start by discussing Hotwire, the libraries it comprises, and the role each plays in building modern applications using Ruby on Rails.

What is Hotwire?

Hotwire (HTML Over The Wire) is a framework proposed by the Basecamp team to simplify how we create web applications. It enables the development of modern, fast, and interactive interfaces without writing large amounts of JavaScript or relying on frameworks like React, Vue, or Angular.

The core idea of Hotwire is to send HTML directly from the server to the user interface, reducing unnecessary processing in the browser. This is achieved through its two main libraries:

1 - Turbo

Turbo is the heart of Hotwire. It optimizes user experience by enabling faster page loads and efficiently updating parts of the interface. Turbo is divided into three key components:

With Turbo, the experience becomes faster and smoother, while the backend remains responsible for generating the HTML.

2 - Stimulus

Stimulus is a lightweight JavaScript framework that allows you to add interactive behaviors in a simple and organized way. It doesn’t compete with Turbo but complements it, enabling you to add "layers" of interactivity where needed.

3 - Hotwire Native: Bringing Hotwire to Native Apps

Hotwire Native extends Hotwire to mobile applications, enabling the integration of a Rails application with native apps (iOS and Android).

Instead of rebuilding the entire logic for a native app, Hotwire Native leverages Turbo to deliver HTML directly to the app using WebViews (a browser embedded within the app). This allows Rails to remain the core of the application, while the mobile app simply renders and supplements it with native functionalities.

How does Hotwire Native work?

  1. The process is straightforward: Rails continues to handle requests and send HTML, just like in web applications.

  2. The mobile app (iOS or Android) uses Turbo Native to display the HTML within a WebView.

  3. Native functionalities (e.g., modals, buttons, or animations) are implemented directly in the native app and can be triggered as needed.

Why use Hotwire Native?

In Summary

Hotwire is a framework that replaces JavaScript/JSON with HTML to streamline and speed up web applications.

Turbo, part of Hotwire, delivers HTML fragments from the server to the interface.

Hotwire Native bridges Hotwire to mobile apps, using WebViews and native functionalities to deliver a powerful hybrid experience.