โšก

Turbo & Hotwire

SPA-like UX without JavaScript

Hotwire is the default frontend framework in Rails 7, consisting of 3 components.

1. Turbo Drive: Intercepts all link clicks and form submissions, replacing only the <body> instead of full page reloads. Works automatically without configuration.

2. Turbo Frames: Independently update specific areas of a page.
Define frames with turbo_frame_tag "post_123" do ... end, and clicking links inside a frame replaces content only within that frame.

3. Turbo Streams: Server instructs 8 types of DOM manipulations.
Actions like turbo_stream.append, prepend, replace, update, remove, before, after, morph directly manipulate specific DOM elements from the server.

Combined with Action Cable, real-time updates are also possible.

Architecture Diagram

๐Ÿš—
Turbo Drive
Auto-AJAX all links/forms
Only replaces &lt;body&gt;
No setup needed!
๐Ÿ–ผ๏ธ
Turbo Frames
Update specific areas independently
turbo_frame_tag
Inline editing
๐ŸŒŠ
Turbo Streams
Serverโ†’Client DOM manipulation
append, remove ...
Real-time updates
Turbo Stream 8 actions:
append
prepend
replace
update
remove
before
after
morph
Traditional (React/Vue)
Server โ†’ JSON โ†’ Client rendering
Hotwire
Server โ†’ HTML โ†’ Insert into Client
Key point: <strong>HTML Over The Wire</strong> โ€” server sends HTML, Turbo partially updates the page

Key Points

1

Turbo Drive: auto-AJAXifies links/forms (no config needed)

2

Define independent update areas with turbo_frame_tag

3

Links inside frames replace only within the frame

4

Turbo Stream instructs DOM operations from server (append, remove, etc.)

5

Respond with respond_to { |format| format.turbo_stream { ... } }

6

Action Cable + Turbo Stream = real-time updates

Pros

  • Minimal JavaScript โ€” maintains server rendering
  • SPA-level UX (flicker-free page transitions)
  • Built into Rails 7 โ€” no additional installation
  • SEO friendly (server rendering)

Cons

  • May conflict with existing JavaScript libraries
  • Turbo Drive may cause unexpected behavior
  • Need to check Network tab when debugging
  • Smaller community compared to React/Vue

Use Cases

Real-time comment addition (turbo_stream.append) Inline editing (turbo_frame) Infinite scroll Auto flash message add/remove Real-time notifications