Convert Figma logo to code with AI

hotwired logoturbo

The speed of a single-page web application without having to write any JavaScript

6,701
427
6,701
308

Top Related Projects

Classic version of Turbolinks. Now deprecated in favor of Turbolinks 5.

22,320

A full-stack framework for Laravel that takes the pain out of building dynamic UIs.

27,910

A rugged, minimal framework for composing JavaScript behavior in your markup.

A collection of composable behaviors for your Stimulus Controllers

12,614

A modest JavaScript framework for the HTML you already have

A framework for building reusable, testable & encapsulated view components in Ruby on Rails.

Quick Overview

Hotwired/turbo is a JavaScript framework that accelerates web application development by providing a set of tools for creating responsive, dynamic interfaces without writing custom JavaScript. It's part of the Hotwire suite and is designed to work seamlessly with server-side frameworks like Ruby on Rails.

Pros

  • Simplifies complex JavaScript interactions with declarative HTML attributes
  • Improves page load times by only updating changed content
  • Seamless integration with server-side frameworks, especially Ruby on Rails
  • Reduces the need for custom JavaScript code in many scenarios

Cons

  • Learning curve for developers accustomed to traditional JavaScript frameworks
  • Limited flexibility compared to full-featured JavaScript frameworks
  • May require server-side changes to fully leverage its capabilities
  • Not ideal for highly interactive, single-page applications

Code Examples

  1. Turbo Drive navigation:
<a href="/articles" data-turbo-frame="content">Load Articles</a>

This link will load the articles page into a Turbo Frame with the ID "content" without a full page reload.

  1. Turbo Stream update:
<turbo-stream action="replace" target="article_1">
  <template>
    <div id="article_1">Updated article content</div>
  </template>
</turbo-stream>

This Turbo Stream will replace the content of an element with ID "article_1" with the new content.

  1. Turbo Frame lazy loading:
<turbo-frame id="comments" src="/comments">
  <p>Loading comments...</p>
</turbo-frame>

This Turbo Frame will lazy load comments from the "/comments" URL, displaying a loading message until the content is fetched.

Getting Started

To get started with Hotwired/turbo in a Rails application:

  1. Add to your Gemfile:

    gem 'turbo-rails'
    
  2. Run:

    bundle install
    rails turbo:install
    
  3. In your application.js, add:

    import "@hotwired/turbo-rails"
    
  4. In your layout file, add:

    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>
    <%= turbo_include_tags %>
    

Now you can start using Turbo in your Rails application by adding data attributes to your HTML elements and leveraging Turbo Frames and Streams.

Competitor Comparisons

Classic version of Turbolinks. Now deprecated in favor of Turbolinks 5.

Pros of Turbolinks-classic

  • Simpler implementation and easier to understand for developers new to the concept
  • Better compatibility with older browsers and legacy JavaScript code
  • Smaller file size and potentially faster initial load times

Cons of Turbolinks-classic

  • Limited features compared to Turbo, lacking advanced capabilities like Frames and Streams
  • Less flexibility in handling complex dynamic content updates
  • No built-in progress bar or loading indicator

Code Comparison

Turbolinks-classic:

// Turbolinks event listener
document.addEventListener("turbolinks:load", function() {
  // Your JavaScript code here
});

Turbo:

// Turbo event listener
document.addEventListener("turbo:load", function() {
  // Your JavaScript code here
});

Summary

Turbo is the successor to Turbolinks-classic, offering more advanced features and better integration with modern web development practices. While Turbolinks-classic is simpler and may be suitable for smaller projects or those with legacy constraints, Turbo provides a more comprehensive solution for building responsive and dynamic web applications. The transition from Turbolinks-classic to Turbo is relatively straightforward, with similar event handling and core concepts, making it an attractive upgrade path for existing projects.

22,320

A full-stack framework for Laravel that takes the pain out of building dynamic UIs.

Pros of Livewire

  • Tighter integration with PHP backend, allowing for easier state management
  • Full-stack framework with built-in UI components and form handling
  • Simpler learning curve for PHP developers

Cons of Livewire

  • Limited to Laravel ecosystem, less flexible for other frameworks
  • Potentially higher server load due to more frequent backend interactions
  • Slightly more verbose syntax compared to Turbo

Code Comparison

Livewire component:

class Counter extends Component
{
    public $count = 0;

    public function increment()
    {
        $this->count++;
    }
}

Turbo Frame:

<turbo-frame id="counter">
  <p>Count: <%= @count %></p>
  <button data-action="click->counter#increment">Increment</button>
</turbo-frame>

Summary

Livewire offers a more integrated PHP-centric approach, while Turbo provides a lightweight, framework-agnostic solution for building reactive interfaces. Livewire excels in Laravel projects with complex server-side logic, whereas Turbo shines in scenarios requiring minimal server interaction and broader framework compatibility. The choice between the two depends on the specific project requirements, team expertise, and desired level of backend integration.

27,910

A rugged, minimal framework for composing JavaScript behavior in your markup.

Pros of Alpine

  • Lightweight and minimal, with a smaller learning curve
  • Can be easily added to existing projects without major refactoring
  • More flexible for creating custom interactive components

Cons of Alpine

  • Less opinionated, requiring more manual setup for larger applications
  • Lacks built-in SPA-like navigation and page updates
  • Limited ecosystem compared to Turbo's integration with Hotwire stack

Code Comparison

Alpine:

<div x-data="{ open: false }">
    <button @click="open = !open">Toggle</button>
    <div x-show="open">Content</div>
</div>

Turbo:

<turbo-frame id="messages">
    <%= render @messages %>
</turbo-frame>
<%= turbo_stream_from "messages" %>

Alpine focuses on declarative, component-level interactivity, while Turbo emphasizes server-driven, full-page updates and navigation. Alpine is more suited for adding interactivity to static sites or enhancing existing applications, whereas Turbo shines in Ruby on Rails ecosystems and applications requiring seamless page transitions. The choice between them depends on the project's requirements, existing tech stack, and desired level of control over client-side interactions.

A collection of composable behaviors for your Stimulus Controllers

Pros of stimulus-use

  • Provides additional utilities and behaviors for Stimulus controllers
  • Offers a collection of composable controllers for common UI patterns
  • Enhances Stimulus with lifecycle callbacks and state management

Cons of stimulus-use

  • Requires Stimulus as a dependency, limiting its standalone use
  • May introduce additional complexity for simple projects
  • Smaller community and ecosystem compared to Turbo

Code Comparison

Turbo:

import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  connect() {
    this.element.textContent = "Hello, Turbo!"
  }
}

stimulus-use:

import { Controller } from "stimulus"
import { useIntersection } from "stimulus-use"

export default class extends Controller {
  connect() {
    useIntersection(this)
  }
  appear() {
    this.element.textContent = "I'm visible!"
  }
}

Summary

While Turbo focuses on providing a complete solution for building modern web applications with minimal JavaScript, stimulus-use extends Stimulus with additional utilities and behaviors. Turbo offers a more comprehensive approach to building reactive interfaces, whereas stimulus-use enhances Stimulus controllers with specific features like intersection observers and lifecycle hooks. The choice between the two depends on the project's requirements and the developer's preference for either a full-stack solution or enhanced controller functionality.

12,614

A modest JavaScript framework for the HTML you already have

Pros of Stimulus

  • Lightweight and focused on enhancing existing HTML
  • Easier to learn and implement for developers familiar with HTML
  • More flexible for adding interactivity to specific elements

Cons of Stimulus

  • Limited built-in functionality compared to Turbo
  • Requires more custom JavaScript for complex interactions
  • Less suited for full page updates and navigation

Code Comparison

Stimulus:

import { Controller } from "stimulus"

export default class extends Controller {
  static targets = [ "name" ]
  greet() {
    console.log(`Hello, ${this.nameTarget.value}!`)
  }
}

Turbo:

<turbo-frame id="messages">
  <h1>Messages</h1>
  <ul>
    <%= render @messages %>
  </ul>
</turbo-frame>

Stimulus focuses on adding behavior to existing HTML elements, while Turbo provides a higher-level abstraction for updating page content and handling navigation. Stimulus is more suitable for adding interactivity to specific parts of a page, whereas Turbo excels at managing full page updates and navigation without full page reloads. The choice between the two depends on the specific needs of your project, with many developers using both in combination for a comprehensive front-end solution.

A framework for building reusable, testable & encapsulated view components in Ruby on Rails.

Pros of view_component

  • Encourages modular, reusable UI components with encapsulated logic
  • Improves testability of view code with unit tests for components
  • Enhances performance through caching and lazy rendering of components

Cons of view_component

  • Requires a shift in development paradigm and potential refactoring of existing views
  • Limited to server-side rendering, unlike Turbo's client-side capabilities
  • May introduce additional complexity for simple view elements

Code Comparison

view_component:

class ButtonComponent < ViewComponent::Base
  def initialize(label:, url:)
    @label = label
    @url = url
  end
end

Turbo:

<turbo-frame id="my-frame">
  <a href="/some-path" data-turbo-method="post">Click me</a>
</turbo-frame>

Key Differences

  • view_component focuses on creating reusable UI components with Ruby classes
  • Turbo emphasizes enhancing page interactions and reducing full page reloads
  • view_component is primarily server-side, while Turbo operates on both client and server
  • Turbo provides a more comprehensive solution for SPA-like experiences
  • view_component integrates seamlessly with existing Rails view patterns

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Turbo

Turbo uses complementary techniques to dramatically reduce the amount of custom JavaScript that most web applications will need to write:

  • Turbo Drive accelerates links and form submissions by negating the need for full page reloads.
  • Turbo Frames decompose pages into independent contexts, which scope navigation and can be lazily loaded.
  • Turbo Streams deliver page changes over WebSocket or in response to form submissions using just HTML and a set of CRUD-like actions.
  • Turbo Native lets your majestic monolith form the center of your native iOS and Android apps, with seamless transitions between web and native sections.

It's all done by sending HTML over the wire. And for those instances when that's not enough, you can reach for the other side of Hotwire, and finish the job with Stimulus.

Read more on turbo.hotwired.dev.

Contributing

Please read CONTRIBUTING.md.

© 2024 37signals LLC.

NPM DownloadsLast 30 Days