Configs2026年5月14日·1 分钟阅读

Hotwire Turbo — Fast Web Apps with HTML Over the Wire

Turbo is the core of the Hotwire approach to building modern web applications. It speeds up navigation by replacing full page loads with partial HTML updates, delivering SPA-like responsiveness without writing custom JavaScript. Turbo is used by default in Ruby on Rails and works with any backend.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Hotwire Turbo Overview
通用 CLI 安装命令
npx tokrepo install eea5bae1-4f6e-11f1-9bc6-00163e2b0d79

Introduction

Turbo is a JavaScript library from the Hotwire suite that makes web applications feel fast by intercepting navigations and form submissions, fetching HTML from the server, and merging it into the current page. Instead of building a JSON API and rendering on the client with a JavaScript framework, you send HTML from the server and let Turbo handle the page updates. This keeps the programming model simple while delivering snappy user experiences.

What Hotwire Turbo Does

  • Intercepts link clicks and replaces the page body with server-rendered HTML without a full reload (Turbo Drive)
  • Decomposes pages into independent frames that load and update asynchronously (Turbo Frames)
  • Streams HTML fragments over WebSocket or SSE to update specific parts of the page in real time (Turbo Streams)
  • Supports morphing updates that preserve DOM state like scroll position and form values
  • Handles form submissions with automatic redirect following and error rendering

Architecture Overview

Turbo is split into three subsystems. Turbo Drive globally intercepts navigation and form submissions, fetching the new page via fetch API and swapping the body element. Turbo Frames scope this behavior to individual sections of the page, each identified by a <turbo-frame> element that can load its content lazily or on user interaction. Turbo Streams deliver targeted DOM mutations (append, prepend, replace, remove, update, morph) via a simple HTML-based protocol over WebSocket, SSE, or HTTP responses. All three subsystems work together without requiring custom JavaScript.

Self-Hosting & Configuration

  • Install via npm or import from a CDN; for Rails, turbo-rails gem provides server-side helpers
  • Turbo Drive activates automatically on all links and forms once the library is imported
  • Add <turbo-frame id="name"> elements to scope navigation to specific page sections
  • Use <turbo-stream> elements in HTTP responses to perform targeted DOM updates
  • For real-time updates, broadcast Turbo Stream fragments via ActionCable (Rails) or any WebSocket/SSE source

Key Features

  • Zero-JavaScript page transitions that feel instant by avoiding full page reloads
  • Frame-based partial updates that keep surrounding page state intact
  • Real-time DOM updates via a declarative HTML streaming protocol
  • Morphing mode that diffs the DOM and preserves input focus, scroll position, and CSS transitions
  • Works with any backend language; not limited to Ruby on Rails

Comparison with Similar Tools

  • htmx — similar HTML-over-the-wire approach with attribute-driven AJAX; more granular control per element but no built-in streaming protocol
  • Livewire — Laravel-specific server-driven UI; tighter PHP integration but framework-locked
  • Phoenix LiveView — Elixir-based server-rendered reactive UI; persistent WebSocket connection for all updates
  • Inertia.js — bridges server-side routing with client-side rendering (React, Vue, Svelte); requires a JavaScript framework
  • Unpoly — progressive enhancement library with layer-based navigation; similar philosophy but different API surface

FAQ

Q: Do I need to write JavaScript with Turbo? A: For most use cases, no. Turbo Drive, Frames, and Streams work through HTML attributes and server-rendered responses. You only write JavaScript for custom behavior via Stimulus (another Hotwire library) or event listeners.

Q: Can Turbo work with backends other than Rails? A: Yes. Turbo is a standalone JavaScript library. Any backend that returns HTML can use Turbo Drive and Frames. Turbo Streams require sending <turbo-stream> elements, which is straightforward in any language.

Q: How does Turbo handle forms with validation errors? A: When a form submission returns a 422 status, Turbo renders the response within the current frame, showing server-rendered error messages without a full page reload.

Q: What is the difference between Turbo and Turbolinks? A: Turbo is the successor to Turbolinks. It includes everything Turbolinks did (fast navigation) plus Frames and Streams for partial page updates and real-time features.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产