Hotwire, which stands for HTML Over-The-Wire, is an alternative approach to building modern web applications without using much JavaScript by sending HTML instead of JSON over the wire.
igor-kasyanchuk / Hotwire for Ruby on Rails Developers

Hotwire for Ruby on Rails Developers
This cheatsheet provides a comprehensive quick reference to Hotwire's core components in Ruby on Rails, including Turbo, Stimulus, and their integration for building fast, dynamic web applications. It covers essential setup steps, code examples, debugging techniques, and best practices to streamline development and improve performance.
- Hotwire for Ruby on Rails Developers
- Turbo Overview
- Turbo Drive
- Turbo Frames
- Turbo Streams
- Custom Turbo Stream Actions
- Stimulus.js Overview
- Stimulus.js Controllers
- Migrating from Rails UJS to Turbo
- Action Cable Integration for Turbo Streams
- Debugging Techniques and Error Handling
- Turbo Caching and Fallback Behaviors
- Hotwire Security Considerations
- Hotwire Performance Tips & Pitfalls
- Hotwire Common Patterns & Best Practices
- Hotwire custom actions and integration with View Components
Hotwire for Ruby on Rails Developers
Introduction to Hotwire
|
It’s designed to work seamlessly with Rails, providing a way to create rich, dynamic user interfaces with significantly less client-side JavaScript. |
Hotwire is composed of Turbo and Stimulus. Turbo handles server-rendered HTML updates and Stimulus provides a lightweight JavaScript framework for enhancing the HTML. |
Hotwire Architecture
The core idea is to leverage server-side rendering for most of the application logic and use HTML updates to change parts of the page. Here’s a simplified diagram:
|
|
Benefits of Hotwire
|
Turbo Drive
Turbo Drive automatically speeds up links and form submissions by intercepting them and making them into |
To disable Turbo Drive on a specific link:
To disable Turbo Drive entirely:
|
It also maintains a persistent history and provides advanced visit control. |
Example of using Turbo Drive to navigate:
|
Turbo Frames
Turbo Frames allow you to divide a page into independent sections that can be updated individually. |
A Turbo Frame looks like this:
|
When a frame’s content changes, only that frame is updated, not the entire page. This reduces bandwidth and makes for a snappier user experience. |
Example of updating a Turbo Frame:
|
Turbo Streams
Turbo Streams deliver page changes as fragments of HTML to be appended, prepended, replaced, updated, or removed. |
Example:
|
These streams are sent over WebSocket connections, or after form submissions and link clicks. |
Another example:
|
Stimulus.js
Stimulus is a modest JavaScript framework for augmenting your HTML. It doesn’t take over the entire page; instead, it’s designed to work well with server-rendered HTML. |
A Stimulus controller looks like this:
|
It connects JavaScript objects to elements in your HTML using data attributes. |
And the corresponding HTML:
|
Rails Integration
Rails provides excellent support for Hotwire through the |
Ensure that you include |
You can generate a new Rails application with Hotwire pre-configured using the
|
Practical Examples
Consider a simple to-do list application. With Hotwire, adding a new to-do item involves submitting a form, the server renders the new item as HTML, and Turbo Streams append it to the list without a full page reload. This is much simpler than implementing the same functionality with a traditional JavaScript framework, which would require writing API endpoints, handling JSON responses, and manually updating the DOM. |
Another common use case is real-time updates. For example, a chat application can use Turbo Streams over WebSockets to push new messages to all connected clients in real time. The server renders the message as HTML, and Turbo Streams ensure it’s instantly displayed in the chat window. |
Hotwire Resources
Hotwire Official Website - Official documentation and guides for Hotwire. |
Turbo Handbook - Comprehensive guide to Turbo. |
Stimulus Handbook - Comprehensive guide to Stimulus. |
Hotwire Source Code (GitHub) - Source code for Turbo and Stimulus. |
GoRails Hotwire Tutorials - A collection of Hotwire tutorials on GoRails. |
Drifting Ruby Hotwire Episodes - Hotwire tutorials and screencasts. |
Hotwire Newsletter - Stay updated with the latest news and updates from the Hotwire community. |
Stimulus Components - A curated collection of reusable Stimulus components. |
Masilotti.com Newsletter - Insights and articles on modern web development, including Hotwire. |
Turbo Overview
Turbo Fundamentals
Turbo is a suite of techniques for building modern web applications by sending HTML over the wire. |
Turbo consists of:
|
Turbo Drive
Turbo Drive intercepts all clicks on This makes navigation feel instantaneous. |
How it works:
|
Example:
Clicking this link triggers a Turbo Drive request. |
To disable Turbo Drive on a specific link, use the
|
Turbo Frames
Turbo Frames allow you to break a page into independent sections that can be updated individually. Each frame is defined by a |
Example:
|
When a link or form inside a Turbo Frame is clicked, Turbo Drive only updates the content within that frame. This isolates updates and improves perceived performance. |
Lazy Loading with
This loads the comments section only when the frame is visible, improving initial page load time. |
Turbo Streams
Turbo Streams deliver targeted updates to the page via WebSocket, SSE (Server-Sent Events), or as a result of form submissions. They consist of actions (like |
Example:
This appends a new comment to the element with id |
To broadcast Turbo Streams from a model callback:
|
Available Actions: (and more)
|
To handle Turbo Stream responses in JavaScript:
|
Installation and Setup
|
|
|
|
Gotchas and Considerations
JavaScript Execution: Turbo Drive preserves JavaScript state across page visits. Ensure your JavaScript is idempotent and handles Turbo Drive events appropriately (e.g., |
Form Submissions: Ensure your forms are set up to handle Turbo Drive. Use |
SEO: Turbo enhances user experience without negatively impacting SEO, as the server still renders full HTML pages. |
Accessibility: Ensure your Turbo-powered application remains accessible by using semantic HTML and ARIA attributes. |
Testing: Test your Turbo-powered features using system tests to ensure they function as expected in a browser environment. |
Turbo Drive
Turbo Drive Overview
Turbo Drive enhances web application speed by intercepting clicks on links and form submissions. |
When a Turbo Drive-enabled link is clicked:
|
Enabling Turbo Drive
Turbo Drive is enabled by default in Rails 7 when using the |
To explicitly enable Turbo Drive, include the Turbo JavaScript file in your application’s JavaScript bundle. For example, using webpacker or jsbundling-rails, ensure the following is present in your
|
Disabling Turbo Drive
You can disable Turbo Drive on specific links or forms by adding the |
Example (Link):
|
Example (Form):
|
To disable Turbo Drive application-wide (not generally recommended), you can remove the |
Turbo Drive Events
|
Fired before Turbo Drive visits a location. Can be used to prevent the visit by calling |
|
Fired when Turbo Drive starts a visit. |
|
Fired before Turbo Drive caches the page. Useful for cleaning up temporary resources. |
|
Fired before Turbo Drive renders the new page. Allows modification of the new |
|
Fired after Turbo Drive renders the new page. |
|
Fired after Turbo Drive finishes loading the new page. Similar to |
|
Fired after a Turbo Frame is rendered. |
Handling JavaScript with Turbo Drive
Since Turbo Drive replaces the |
Example:
|
For libraries or components that need to be properly disposed of when navigating away from a page, use the |
Example:
|
Troubleshooting Turbo Drive
If you encounter issues with Turbo Drive, such as JavaScript not running or unexpected behavior, check the following:
|
Inspect network requests in your browser’s developer tools to confirm that Turbo Drive is indeed making |
Turbo Frames
Turbo Frames Overview
Turbo Frames allow you to update specific parts of a page without requiring a full page reload. This enhances user experience by making updates feel faster and more responsive. |
They work by wrapping sections of your page in |
This approach reduces server load and network bandwidth, leading to improved performance, especially in complex web applications. |
Basic Implementation
HTML (View) |
|
Rails (Partial - |
|
Explanation |
The |
Lazy Loading with Turbo Frames
HTML (Lazy Loading) |
|
Rails (Controller) |
|
Rails (Partial - |
|
Explanation |
The frame with |
Targeting Turbo Frames
Targeting a specific frame |
You can target a specific Turbo Frame from a link or form using the
This will update the frame with the ID |
Targeting |
Using
|
Targeting |
Using
|
Form Submissions inside Turbo Frames
HTML (Form) |
|
Rails (Controller) |
|
Rails (Partial - |
|
Explanation |
Submitting the form will replace the content within |
Turbo Streams
Introduction to Turbo Streams
Turbo Streams deliver asynchronous updates to the browser by appending, prepending, replacing, updating, or removing elements on a page. They are typically used with Action Cable for real-time updates but can also be triggered by standard controller actions. |
Turbo Streams use specific MIME types ( |
Turbo Streams are an efficient way to update parts of a page without requiring a full page reload, enhancing the user experience. |
They are especially useful for features like live comments, chat applications, and real-time dashboards. |
Turbo Streams leverage the |
Turbo Stream Actions
|
Inserts content at the end of the target element. Example:
|
|
Inserts content at the beginning of the target element. Example:
|
|
Replaces the entire target element with the new content. Example:
|
|
Updates the content inside the target element, leaving the element itself intact. Example:
|
|
Removes the target element from the DOM. Example:
|
Creating Turbo Stream Responses
In your controller, you can respond with Turbo Stream templates to trigger updates. |
Use the |
Example:
|
Alternatively, use |
Broadcasting with Action Cable
Action Cable can broadcast Turbo Streams to update multiple clients in real-time. |
Use Example:
|
In your model or controller, use Example:
|
Ensure Action Cable is properly configured in your Rails application, including setting up the necessary routes and connection class. |
Turbo Stream Templates
Turbo Stream templates are |
These templates are rendered and sent to the client, where Turbo Drive processes them. |
Example:
|
Use partials to keep your templates DRY and maintainable. |
Leverage the |
Targeting Elements
Using IDs |
Target specific elements using their IDs. This is the most common and straightforward approach. Example:
|
Using CSS Selectors |
You can use CSS selectors to target elements, providing more flexibility. Example:
|
Considerations |
Ensure your target elements have unique IDs to avoid unintended updates. When using CSS selectors, be specific to prevent broad changes. |
Advanced Turbo Streams Usage
Combining Multiple Actions: You can combine multiple Turbo Stream actions in a single response. Example:
|
Conditional Updates: Implement conditional logic to determine whether to send a Turbo Stream based on specific conditions. Example:
|
Custom Actions: While less common, you can define custom Turbo Stream actions by extending Turbo Native. |
Error Handling: Implement error handling to gracefully manage situations where Turbo Stream updates fail. |
Custom Turbo Stream Actions
Custom Turbo Stream Actions
Backend (Ruby on Rails) |
Frontend (JavaScript) |
Define helper methods in
|
Define JavaScript functions to handle the custom Turbo Stream actions.
|
Include the helper in your controllers.
|
Ensure your JavaScript is loaded and accessible. Typically, this code is placed in
|
Using
|
Example HTML for a modal:
|
Using
|
Make sure your |
The
|
When a If the function exists, it’s executed; otherwise, an error might occur. |
Ensure the |
For debugging, use |
When passing data from the backend to the frontend using |
Use |
Instead of directly manipulating the DOM, consider using Stimulus controllers within your modals for more complex interactions and state management. This keeps your code organized and maintainable. |
When updating a modal with new content, consider using Turbo Frames to update specific parts of the modal instead of replacing the entire modal. This can improve performance and reduce flicker. |
Always test your custom Turbo Stream actions thoroughly to ensure they behave as expected in different scenarios. Pay attention to edge cases and potential error conditions. |
Consider using custom events to trigger actions within your JavaScript code. This allows for a more decoupled and flexible architecture. |
Example of using a custom event to close a modal:
|
Remember to handle errors gracefully in your JavaScript code. Display user-friendly messages or log errors to the console for debugging purposes. |
For more complex modal interactions, consider using a dedicated modal library or component. This can provide additional features and improve the overall user experience. |
Ensure that your custom Turbo Stream actions are compatible with different browsers and devices. Test your code on a variety of platforms to ensure a consistent experience. |
When using Turbo Streams to update the DOM, be mindful of the potential for race conditions. Ensure that your JavaScript code is properly synchronized to prevent unexpected behavior. |
Document your custom Turbo Stream actions thoroughly. This will make it easier for other developers to understand and maintain your code. |
Stimulus.js Overview
Introduction to Stimulus
Stimulus is a modest JavaScript framework designed for enhancing HTML with dynamic behavior. It’s designed to work well with Turbo, allowing you to build modern web applications without a lot of complex JavaScript. Key features:
|
Stimulus promotes a structured approach to JavaScript in Rails applications, making code more maintainable and easier to understand. |
Core Concepts
Controllers |
JavaScript objects that manage the behavior of DOM elements. They are the primary building blocks of Stimulus applications. |
Targets |
Specific DOM elements within a controller’s scope that the controller can interact with. |
Actions |
Methods in the controller that are triggered by DOM events on elements within the controller’s scope. |
Values |
A way to store and manage data within a controller, making it easy to access and update values from the DOM. |
Setting Up Stimulus
|
|
|
Simple Stimulus Controller Example
Let’s create a simple controller that displays a greeting message.
|
HTML Usage
|
Key Data Attributes
|
Specifies the Stimulus controller to be associated with the HTML element. |
|
Defines a target element within the controller’s scope. |
|
Binds an event to a controller action. |
|
Sets a value on the controller that can be accessed and updated. |
Working with Values
Values allow you to store data directly in the DOM and access it from your Stimulus controllers. Example:
|
Debugging Stimulus
|
Stimulus.js Controllers
Controller Basics
Stimulus.js controllers enhance HTML with behavior.
|
Controllers are defined as ES modules and placed in |
Connecting Controllers to HTML
Use
|
Lifecycle Callbacks
|
Called when the controller is connected to the DOM.
|
|
Called when the controller is disconnected from the DOM.
|
|
Called only once when the controller is instantiated.
|
Actions
Actions respond to DOM events. Use
|
Controller method:
|
Targets
Targets provide direct references to specific elements within a controller’s scope. Define targets in the controller definition, and reference them in your methods.
|
HTML:
|
Values
Values allow you to bind data attributes to typed values in your controller.
|
HTML:
|
CSS Classes
CSS Classes can be toggled on and off using Stimulus. Define class names in the controller, and use the corresponding methods to manipulate them.
|
HTML:
|
Controller Organization
Organize your Stimulus controllers logically within the
|
Using `this.element`
The Example:
In this example, |
Migrating from Rails UJS to Turbo
Why Migrate to Turbo from Rails UJS?
Rails UJS (Unobtrusive JavaScript) is the traditional way Rails handles JavaScript interactions, relying heavily on jQuery. It’s being phased out in favor of Hotwire’s Turbo for several compelling reasons:
|
Moving to Turbo provides a more streamlined and performant experience by default. |
Step-by-Step Migration Guide
|
|
|
|
|
|
Code Examples: Before and After
Rails UJS (Before)
|
Turbo (After)
|
Rails UJS (Before)
|
Turbo (After)
Note: Turbo handles the form submission via AJAX by default. Use Turbo Streams in your controller to update the view after submission. |
Rails UJS (Before - Custom JS Callback)
|
Turbo (After - Turbo Stream) Controller (example):
View (articles/create.turbo_stream.erb):
|
Rails UJS (Before - data-disable-with)
|
Turbo (After - data-turbo-submits-with)
|
Rails UJS (Before - remote link with GET method)
|
**Turbo (After - using data-turbo)
|
Rails UJS (Before - prevent full page reload)
|
Turbo (After - using Turbo events and
|
Action Cable Integration for Turbo Streams
Overview
Integrating Action Cable with Turbo Streams allows you to broadcast real-time updates to your Rails application. This enables features like live comments, real-time notifications, and dynamic content updates without full page reloads. Turbo Streams handle the rendering and updating of specific DOM elements, while Action Cable provides the real-time communication infrastructure. |
This integration involves configuring Action Cable, setting up Turbo Streams, and broadcasting updates from your Rails backend to connected clients. |
Configuration
1. Configure Action Cable: |
Ensure Action Cable is properly configured in your |
2. Setup Redis (optional): |
If using Redis, ensure it’s running and accessible to your Rails application. Update |
3. Mount Action Cable: |
Mount Action Cable in your
|
Creating a Channel
Generate a channel using Rails generators. For example, to create a
|
This creates
|
Broadcasting Turbo Streams
To broadcast Turbo Streams, use the Example: Broadcasting a new comment:
|
In this example,
|
Client-Side Subscription
On the client-side, subscribe to the Action Cable channel using JavaScript. This is typically done in your
|
Ensure that this JavaScript file is included in your application’s JavaScript bundle. |
Displaying Turbo Streams
Make sure that the container to update exists. The container is
|
When the broadcast reaches the client, Turbo Streams automatically updates the DOM based on the specified actions (e.g., |
Example: Real-time Notifications
You can adapt the same principles to implement real-time notifications. Create a
|
Ensure your client-side JavaScript subscribes to the |
Debugging Techniques and Error Handling
General Debugging Strategies
When debugging Hotwire applications, it’s crucial to use browser developer tools and server logs effectively.
|
Set the |
Debugging Turbo Frames
Turbo Frames can sometimes behave unexpectedly if the frame IDs are not unique or if the server response doesn’t match the expected frame. Here’s how to debug them:
|
Example of using
|
Sometimes, content might not load into a Turbo Frame due to JavaScript errors. Check the browser console for JavaScript errors that might be preventing the frame from loading correctly. |
Debugging Turbo Streams
Turbo Streams are used to update parts of the page dynamically. Debugging them involves checking the server response and ensuring the correct stream actions are being applied.
|
Example of using
|
If a Turbo Stream action is not being applied, check the browser console for JavaScript errors. Also, ensure that the target element exists on the page and that the stream action is valid for that element. |
Error Handling in Turbo Streams
Implement error handling on the server-side to gracefully handle exceptions and return appropriate Turbo Stream responses.
|
Example of using
|
In some cases, you may want to prevent Turbo Drive from navigating to a new page on error. You can do this by canceling the |
|
Stimulus Controller Debugging
Stimulus controllers manage the behavior of your HTML elements. Debugging them involves ensuring that the controller is correctly connected and that actions are being triggered as expected.
|
|
If a Stimulus action is not being triggered, check the spelling of the controller and method names in the |
Integration Testing
Write integration tests to ensure that your Hotwire components are working correctly together. Use Capybara or Rails system tests to simulate user interactions and verify the behavior of your application.
|
Example of a Rails system test:
|
When writing integration tests, make sure to wait for Turbo Streams and Turbo Frames to load before asserting on the page content. Use Capybara’s |
Turbo Caching and Fallback Behaviors
Understanding Turbo Caching
Turbo Drive automatically caches pages as you visit them, making subsequent visits feel instantaneous. It leverages the browser’s history API to achieve this. |
When you navigate back or forward, Turbo Drive restores the page from its cache, avoiding a full page reload. |
This caching mechanism primarily targets GET requests. POST, PUT, and DELETE requests trigger a full page reload to ensure data consistency. |
You can control Turbo’s caching behavior using meta tags in your HTML. For instance, to disable caching for a specific page: |
|
This tag instructs Turbo not to cache the current page, ensuring it’s always fetched from the server. |
Alternatively, you can use |
Turbo also respects standard HTTP caching headers like |
For dynamic content, consider using |
If you are using |
Debugging Turbo Caching Issues
When encountering unexpected caching behavior, use your browser’s developer tools to inspect the HTTP cache and verify that pages are being cached and served correctly. |
Check the |
Clear your browser’s cache and cookies to rule out any stale or corrupted cached data. |
Use the |
Inspect the network requests in the developer tools to see if pages are being fetched from the server or served from the cache. |
Verify that your server is sending the correct |
If you’re using a CDN, check its caching configuration and ensure it’s properly caching your assets. |
Consider using a logging framework to track Turbo-related events and identify potential caching issues. |
Handling Cache Fallbacks
In scenarios where the Turbo cache is unavailable (e.g., due to a network error), you can implement fallback behaviors to ensure a smooth user experience. |
One approach is to detect Turbo availability and conditionally perform a full page reload if Turbo is not present: |
|
This JavaScript snippet checks if the |
Another strategy involves using service workers to cache critical assets and provide offline access. Service workers can intercept network requests and serve cached content when the network is unavailable. |
When implementing service workers, ensure they are compatible with Turbo Drive’s caching strategy to avoid conflicts or unexpected behavior. |
Consider using a combination of Turbo Drive caching and service worker caching for optimal performance and resilience. |
If you are using CDN - ensure that proper headers are configured, to enable caching mechanism on the CDN level. |
Fine-Grained Control with Turbo Streams
Turbo Streams offer a more granular way to update specific parts of a page without requiring a full reload. This can be particularly useful for dynamic content updates. |
You can use Turbo Streams to broadcast changes to connected clients via WebSocket connections, ensuring real-time updates. |
To use Turbo Streams, you typically define actions in your Rails controllers that render Turbo Stream templates. For example: |
|
This code appends a new comment to the |
Ensure that your Turbo Stream actions are idempotent to handle potential duplicate broadcasts or re-renders. |
Consider using |
Always test Turbo Streams with different network conditions to ensure they function correctly under varying latency and bandwidth scenarios. |
Turbo Frames for Modular Content
Turbo Frames allow you to isolate sections of a page into independent, cacheable units. This is useful for creating modular and reusable components. |
Each Turbo Frame has a unique |
When a link or form within a Turbo Frame is clicked or submitted, Turbo Drive only updates the content of that specific frame, leaving the rest of the page untouched. |
Here’s an example of a Turbo Frame: |
|
If the content inside a |
|
Use Turbo Frames to break down complex pages into smaller, manageable components, improving performance and maintainability. |
Nested Turbo Frames are supported, allowing for even greater flexibility in structuring your application’s UI. |
Hotwire Security Considerations
CSRF Protection in Hotwire
Rails’ built-in CSRF protection works seamlessly with Hotwire. Ensure |
|
When using Turbo Streams with forms, Rails automatically includes the CSRF token in the form data. No extra steps are required for standard form submissions. |
For non-standard form submissions (e.g., AJAX-like requests with Turbo Streams), ensure the CSRF token is included in the request headers. You can do this via JavaScript: |
|
With jQuery: |
|
Secure Handling of Turbo Streams
Always validate and sanitize data received via Turbo Streams to prevent injection attacks. Ensure that only authorized users can modify specific parts of the page. |
Avoid directly embedding user-supplied data into Turbo Stream actions without proper escaping. Use Rails’ built-in sanitization methods. |
When rendering Turbo Streams in the controller, use the |
|
Implement proper authentication and authorization checks in your controllers to ensure that users can only access or modify resources they are permitted to. |
Use strong parameters to whitelist attributes that can be updated via form submissions or API requests. This helps prevent mass assignment vulnerabilities. |
Content Security Policy (CSP)
Configure a Content Security Policy (CSP) to mitigate the risk of Cross-Site Scripting (XSS) attacks. CSP allows you to define which sources of content (scripts, stylesheets, images, etc.) the browser should trust. |
In your |
|
Adjust the CSP directives based on your application’s needs. Common directives include |
Be mindful of inline scripts and styles, as they are often blocked by CSP unless you use |
When using Stimulus, ensure that your CSP allows the necessary JavaScript files to be loaded and executed. You may need to whitelist the CDN or domain where your Stimulus code is hosted. |
Regularly review and update your CSP to address new threats and ensure compatibility with your application’s dependencies. |
Hotwire Performance Tips & Pitfalls
Optimize Turbo Streams
Partial Page Updates:
|
Batch Turbo Streams:
|
Use
|
Lazy Loading:
|
Avoid Excessive DOM Manipulation: |
Common Pitfalls
Over-reliance on Turbo Frames: |
Ignoring Network Latency: |
Unoptimized Images: |
Excessive JavaScript: |
Neglecting Browser Caching: |
Stimulus Controller Optimization
Debounce Actions:
|
Disconnect Observers:
|
Efficient Data Attributes:
|
Lazy Initialization: |
Reduce DOM Queries:
|
Server-Side Performance
Optimize Database Queries:
|
Caching:
|
Background Jobs:
|
Efficient Rendering: |
Use Indexes: |
Benchmarking and Profiling
Rails Benchmark Tool:
|
Browser Developer Tools: |
Bullet Gem:
|
Rack Mini Profiler:
|
Memory Profiling: |
Turbo Native Considerations
Optimize Asset Size: |
Native Bridge Overhead: |
Offline Support: |
Adaptive Content: |
Preloading: |
Hotwire Common Patterns & Best Practices
Turbo Drive Best Practices
Use Turbo Drive for standard navigation:
|
Ensure idempotent GET requests:
|
Use
|
Handle Turbo Drive events:
|
Leverage Turbo Streams for real-time updates:
|
Turbo Frames Patterns
Nested Frames:
|
Lazy Loading with Frames:
|
Targeting Frames from Forms:
|
Using
|
Fallback Content:
|
Turbo Streams Strategies
Broadcast Updates from Models:
|
Target Specific Users or Groups:
|
Use
|
Custom Turbo Stream Actions:
|
Conditional Broadcasting:
|
Stimulus Controller Conventions
Naming Conventions:
|
Data Attributes for Targets and Actions:
|
Controller Organization:
|
Lifecycle Callbacks:
|
Debouncing and Throttling:
|
Stimulus Advanced Patterns
Using Stores for Shared State:
|
Asynchronous Actions:
|
Dynamic Targets:
|
External Libraries Integration:
|
Form Submission Handling with Stimulus:
|
Performance Optimization
Minimize DOM Manipulations:
|
Optimize Images and Assets:
|
Lazy Loading:
|
Caching Strategies:
|
Code Splitting:
|
Testing Hotwire Applications
System Tests with Capybara:
|
JavaScript Testing with Jest or Mocha:
|
Integration Tests for Turbo Streams:
|
Mocking Turbo Streams in Tests:
|
Using
|
Hotwire custom actions and integration with View Components
Turbo Messages
You can pass many custom actions to Nex this stream action will be captured on JS side
|
With View Components
This is important code |