SlideShare a Scribd company logo
1 of 22
Download to read offline
Hotwire and Turbo
In Ruby on Rails 7
Prajit Bhandari
Introduction to Hotwire
● HTML over the Wire (idea of sending HTML instead of data)
● Default front-end framework for Ruby on Rails application
● Combination of Stimulus , Turbo , and Turbo Drive
● Introduced in Ruby on Rails 6 as optional feature
● Included by default in Ruby on Rails 7
● Goal: SPA(Single Page Application) and application speed up
Installing Turbo in Rails application
● GemFile
gem 'turbo-rails'
gem 'stimulus-rails'
● execute bundle install in terminal
● Application.js
import "@hotwired/turbo-rails"
import "./controllers"
Benefits of using Hotwire
● Reduce server requests: Use Turbo Streams to update parts of a page without a full
server request.
● Eliminate page reloads: Use Turbo Drive to load linked pages in the background and
swap out only the content that needs to be changed.
● Improve perceived performance: Use Stimulus.js to progressively enhance the user
interface, making it feel faster and more responsive.
● Optimize network usage: Use Turbo Streams to send only the data that needs to be
updated on the page, reducing the amount of data transferred between server and
client.
● Reduce development time: Use Hotwire's cohesive set of tools to avoid learning
and integrating multiple third-party libraries.
● Security: CSRF and XSS attack prevention by default.
Turbo in Hotwire
● JS library built on top of Hotwire and enables real-time updates
● Comprises of Turbo Frame and Turbo Stream
● SPA without having to write much custom JS
● Focuses on providing high-performance
● Low-overhead way to build web apps
Turbo Frame in Turbo
● Independent pieces of a web page that can be appended, prepended, replaced, or
removed without a complete page refresh.
● All clicks on links and form submissions are now AJAX requests by default
● Syntax: <%= turbo_frame_tag ‘frame_name’ , target: ‘target_type’ , src: ‘url’ do %>
#code blocks
<% end %>
● Turbo Frame name are usually specified with dom_id(@instance)
● Html elements wrapped under a turbo-frame-tag references the same tag name in the
redirected url.
● Turbo Frame holds “src”a data-property which contains the url of an endpoint to fetch
content from the respective url
Turbo Frame Type
● Eager loaded Frame:
- Works like the basic frame, but the content is loaded from a remote src first.
- <% turbo_frame_tag src="/messages" %>
- # Content will be replaced when /messages has been loaded.
- <% end %>
● Lazy loaded Frame:
- Like an eager-loaded frame, but the content is not loaded from src until the frame is
visible.
- <% turbo_frame_tag src="/messages" loading = lazy %>
- #Content will be replaced when the frame becomes visible and /messages has
been loaded.
- <% end %>
Turbo Frame Target
● _self: The linked document will open in the same frame or window as the current
document.
● _parent: The linked document will open in the parent frame of the current frame
or window. If there is no parent, it behaves like _self.
● _blank: The linked document will open in a new, unnamed window or tab.
● _top: The linked document will open in the top-level frame or window. If there
are nested frames, all frames will be replaced with the linked document.
Nested Turbo Frame
● Need to render a turbo frame inside another turbo frame.
● Allows for more faster loading times.
● Multiple parts of a page can be updated independently, rather than having to
reload the entire page.
● <%= turbo_frame_tag nested_dom_id(instance1, instance2) % do >
● <%# content %>
● <% end %>
Turbo Stream in Turbo
● Forms in Rails 7 are now submitted with the TURBO_STREAM format
● View file is implemented as <file/endpoint name>.turbo_stream.erb
● Turbo Stream format is mechanism for updating parts of a webpage
without requiring a full page reload.
● This allows for faster and more responsive user experiences, as only the
necessary components of the page are updated.
Turbo Drive
● With turbo drive, data-turbo=’true’ is enabled on a turbo frame
● Extension of Turbo that allows for real-time updates to web pages without the need for a
full page refresh.
● Intercepts form submissions and link clicks, and sending the data via a streaming
connection to the server, which then updates the page without the need for a full page
refresh
● Adding data-turbo=’false’ data attribute on the HTML element disables turbo
A Basic Flow of Hotwire and Turbo
Stimulus
● JS framework for adding behavior to your HTML.
● lightweight and efficient, with a small code footprint and minimal
performance overhead.
● A user-initiated event that triggers a state change in the application
● Allows you to add JavaScript to your HTML by using "controllers" that
can respond to events on the page
How does Stimulus JS work?
● Intercepts events: button clicks, form submissions, and link clicks
● Can be handled by the Hotwire JavaScript library, which listens for events on the
page and sends an HTTP request to the server.
● The server then responds with the updated HTML and JavaScript necessary to
update the state of the application, which is then rendered in the browser.
● Uses a declarative approach:
<button data-controller="controller_name"
data-#{controller-name}–#{attribute}-value=”value”
data-action="click->controller_name#method_name">Greet</button>
Boiler Plate of Stimulus js
import { Controller } from "stimulus"
export default class extends Controller {
static values = { name: String}
initialize() {
console.log("Controller initialized once for default values")
}
connect() {
console.log("Controller connected")
}
method_name() {
const name = this.nameValue || "World"
console.log(`Hello, ${name}!`)
}
}
Index.js
● import { application } from './application'
● import DemoController from './demo_controller.js'
● application.register('demo', DemoController)
● Note: This controller files should be placed inside javascript/controller dir
BEM Methodology
● Block Element Modifier
● A CSS architecture preferred in Hotwire and Turbo
● Provides modularity with no overlapping issues with the element
● BEM is a natural fit with Stimulus to add behavior to HTML elements.
● Example:
References
● https://www.hotrails.dev/
● https://stimulus.hotwired.dev/reference/controllers

More Related Content

What's hot

Node.js Express
Node.js  ExpressNode.js  Express
Node.js ExpressEyal Vardi
 
RESTful API 설계
RESTful API 설계RESTful API 설계
RESTful API 설계Jinho Yoo
 
Oracle REST Data Services Best Practices/ Overview
Oracle REST Data Services Best Practices/ OverviewOracle REST Data Services Best Practices/ Overview
Oracle REST Data Services Best Practices/ OverviewKris Rice
 
Introducing Async/Await
Introducing Async/AwaitIntroducing Async/Await
Introducing Async/AwaitValeri Karpov
 
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...Edureka!
 
PHP と SAPI と ZendEngine3 と
PHP と SAPI と ZendEngine3 とPHP と SAPI と ZendEngine3 と
PHP と SAPI と ZendEngine3 とdo_aki
 
Tomcat and apache httpd training
Tomcat and apache httpd trainingTomcat and apache httpd training
Tomcat and apache httpd trainingFranck SIMON
 
From Spring Framework 5.3 to 6.0
From Spring Framework 5.3 to 6.0From Spring Framework 5.3 to 6.0
From Spring Framework 5.3 to 6.0VMware Tanzu
 
Intro to Jinja2 Templates - San Francisco Flask Meetup
Intro to Jinja2 Templates - San Francisco Flask MeetupIntro to Jinja2 Templates - San Francisco Flask Meetup
Intro to Jinja2 Templates - San Francisco Flask MeetupAlan Hamlett
 
The Enterprise Case for Node.js
The Enterprise Case for Node.jsThe Enterprise Case for Node.js
The Enterprise Case for Node.jsNodejsFoundation
 
進擊的前端工程師:今天就用 JSON Server 自己打造 API 吧!
進擊的前端工程師:今天就用 JSON Server 自己打造 API 吧!進擊的前端工程師:今天就用 JSON Server 自己打造 API 吧!
進擊的前端工程師:今天就用 JSON Server 自己打造 API 吧!Will Huang
 
What is JavaScript? Edureka
What is JavaScript? EdurekaWhat is JavaScript? Edureka
What is JavaScript? EdurekaEdureka!
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6Rob Eisenberg
 
twMVC#44 如何測試與保護你的 web application with playwright
twMVC#44 如何測試與保護你的 web application with playwrighttwMVC#44 如何測試與保護你的 web application with playwright
twMVC#44 如何測試與保護你的 web application with playwrighttwMVC
 
APEX Interactive Grid API Essentials: The Stuff You Will Really Use
APEX Interactive Grid API Essentials:  The Stuff You Will Really UseAPEX Interactive Grid API Essentials:  The Stuff You Will Really Use
APEX Interactive Grid API Essentials: The Stuff You Will Really UseKaren Cannell
 
gRPC on .NET Core - NDC Sydney 2019
gRPC on .NET Core - NDC Sydney 2019gRPC on .NET Core - NDC Sydney 2019
gRPC on .NET Core - NDC Sydney 2019James Newton-King
 

What's hot (20)

Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
Php introduction
Php introductionPhp introduction
Php introduction
 
RESTful API 설계
RESTful API 설계RESTful API 설계
RESTful API 설계
 
Oracle REST Data Services Best Practices/ Overview
Oracle REST Data Services Best Practices/ OverviewOracle REST Data Services Best Practices/ Overview
Oracle REST Data Services Best Practices/ Overview
 
Introducing Async/Await
Introducing Async/AwaitIntroducing Async/Await
Introducing Async/Await
 
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
 
PHP と SAPI と ZendEngine3 と
PHP と SAPI と ZendEngine3 とPHP と SAPI と ZendEngine3 と
PHP と SAPI と ZendEngine3 と
 
Tomcat and apache httpd training
Tomcat and apache httpd trainingTomcat and apache httpd training
Tomcat and apache httpd training
 
From Spring Framework 5.3 to 6.0
From Spring Framework 5.3 to 6.0From Spring Framework 5.3 to 6.0
From Spring Framework 5.3 to 6.0
 
Express js
Express jsExpress js
Express js
 
Intro to Jinja2 Templates - San Francisco Flask Meetup
Intro to Jinja2 Templates - San Francisco Flask MeetupIntro to Jinja2 Templates - San Francisco Flask Meetup
Intro to Jinja2 Templates - San Francisco Flask Meetup
 
The Enterprise Case for Node.js
The Enterprise Case for Node.jsThe Enterprise Case for Node.js
The Enterprise Case for Node.js
 
進擊的前端工程師:今天就用 JSON Server 自己打造 API 吧!
進擊的前端工程師:今天就用 JSON Server 自己打造 API 吧!進擊的前端工程師:今天就用 JSON Server 自己打造 API 吧!
進擊的前端工程師:今天就用 JSON Server 自己打造 API 吧!
 
What is JavaScript? Edureka
What is JavaScript? EdurekaWhat is JavaScript? Edureka
What is JavaScript? Edureka
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
 
Bootstrap ppt
Bootstrap pptBootstrap ppt
Bootstrap ppt
 
twMVC#44 如何測試與保護你的 web application with playwright
twMVC#44 如何測試與保護你的 web application with playwrighttwMVC#44 如何測試與保護你的 web application with playwright
twMVC#44 如何測試與保護你的 web application with playwright
 
APEX Interactive Grid API Essentials: The Stuff You Will Really Use
APEX Interactive Grid API Essentials:  The Stuff You Will Really UseAPEX Interactive Grid API Essentials:  The Stuff You Will Really Use
APEX Interactive Grid API Essentials: The Stuff You Will Really Use
 
gRPC on .NET Core - NDC Sydney 2019
gRPC on .NET Core - NDC Sydney 2019gRPC on .NET Core - NDC Sydney 2019
gRPC on .NET Core - NDC Sydney 2019
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 

Similar to Hotwire and Turbo - Knowledge Ketchup - Prajit Bhandari.pdf

Client Side Measurement & Performance With Rails
Client Side Measurement & Performance With RailsClient Side Measurement & Performance With Rails
Client Side Measurement & Performance With RailsEric Falcao
 
Developing high performance and responsive web apps using web worker
Developing high performance and responsive web apps using web workerDeveloping high performance and responsive web apps using web worker
Developing high performance and responsive web apps using web workerSuresh Patidar
 
2018 Google Mobile First Index - Speed up Apache & Web for SEO
2018 Google Mobile First Index - Speed up Apache & Web for SEO2018 Google Mobile First Index - Speed up Apache & Web for SEO
2018 Google Mobile First Index - Speed up Apache & Web for SEOEmilio Rodríguez García
 
Angular.js for beginners
Angular.js for beginners Angular.js for beginners
Angular.js for beginners Basia Madej
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpackNodeXperts
 
Rest web service_with_spring_hateoas
Rest web service_with_spring_hateoasRest web service_with_spring_hateoas
Rest web service_with_spring_hateoasZeid Hassan
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...WebStackAcademy
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with DancerDave Cross
 
Architecting single-page front-end apps
Architecting single-page front-end appsArchitecting single-page front-end apps
Architecting single-page front-end appsZohar Arad
 
Developing High Performance Web Apps
Developing High Performance Web AppsDeveloping High Performance Web Apps
Developing High Performance Web AppsTimothy Fisher
 
Build single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEMBuild single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEMAdobeMarketingCloud
 
Build single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEMBuild single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEMAdobeMarketingCloud
 
Build single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEMBuild single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEMconnectwebex
 
Asp .net web form fundamentals
Asp .net web form fundamentalsAsp .net web form fundamentals
Asp .net web form fundamentalsGopal Ji Singh
 
React - The JavaScript Library for User Interfaces
React - The JavaScript Library for User InterfacesReact - The JavaScript Library for User Interfaces
React - The JavaScript Library for User InterfacesJumping Bean
 
Building high performing web pages
Building high performing web pagesBuilding high performing web pages
Building high performing web pagesNilesh Bafna
 

Similar to Hotwire and Turbo - Knowledge Ketchup - Prajit Bhandari.pdf (20)

Client Side Measurement & Performance With Rails
Client Side Measurement & Performance With RailsClient Side Measurement & Performance With Rails
Client Side Measurement & Performance With Rails
 
React loadable
React loadableReact loadable
React loadable
 
Developing high performance and responsive web apps using web worker
Developing high performance and responsive web apps using web workerDeveloping high performance and responsive web apps using web worker
Developing high performance and responsive web apps using web worker
 
2018 Google Mobile First Index - Speed up Apache & Web for SEO
2018 Google Mobile First Index - Speed up Apache & Web for SEO2018 Google Mobile First Index - Speed up Apache & Web for SEO
2018 Google Mobile First Index - Speed up Apache & Web for SEO
 
Angular.js for beginners
Angular.js for beginners Angular.js for beginners
Angular.js for beginners
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpack
 
Rest web service_with_spring_hateoas
Rest web service_with_spring_hateoasRest web service_with_spring_hateoas
Rest web service_with_spring_hateoas
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
 
Ajax
Ajax Ajax
Ajax
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with Dancer
 
Architecting single-page front-end apps
Architecting single-page front-end appsArchitecting single-page front-end apps
Architecting single-page front-end apps
 
Developing High Performance Web Apps
Developing High Performance Web AppsDeveloping High Performance Web Apps
Developing High Performance Web Apps
 
Build single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEMBuild single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEM
 
Build single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEMBuild single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEM
 
Build single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEMBuild single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEM
 
Routing
RoutingRouting
Routing
 
Asp .net web form fundamentals
Asp .net web form fundamentalsAsp .net web form fundamentals
Asp .net web form fundamentals
 
Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations
 
React - The JavaScript Library for User Interfaces
React - The JavaScript Library for User InterfacesReact - The JavaScript Library for User Interfaces
React - The JavaScript Library for User Interfaces
 
Building high performing web pages
Building high performing web pagesBuilding high performing web pages
Building high performing web pages
 

More from GurzuInc

Power of documentation | Aarati Shah | Gurzu.pdf
Power of documentation | Aarati Shah | Gurzu.pdfPower of documentation | Aarati Shah | Gurzu.pdf
Power of documentation | Aarati Shah | Gurzu.pdfGurzuInc
 
The Art of Refactoring | Asmit Ghimire | Gurzu.pdf
The Art of Refactoring | Asmit Ghimire | Gurzu.pdfThe Art of Refactoring | Asmit Ghimire | Gurzu.pdf
The Art of Refactoring | Asmit Ghimire | Gurzu.pdfGurzuInc
 
I'm Programmer _ Ganesh Kunwar _ Gurzu.pdf
I'm Programmer _ Ganesh Kunwar _ Gurzu.pdfI'm Programmer _ Ganesh Kunwar _ Gurzu.pdf
I'm Programmer _ Ganesh Kunwar _ Gurzu.pdfGurzuInc
 
Obtaining Your Tax Clearance Certificate_ A Quick Guide | Deepak Rai | Gurzu.pdf
Obtaining Your Tax Clearance Certificate_ A Quick Guide | Deepak Rai | Gurzu.pdfObtaining Your Tax Clearance Certificate_ A Quick Guide | Deepak Rai | Gurzu.pdf
Obtaining Your Tax Clearance Certificate_ A Quick Guide | Deepak Rai | Gurzu.pdfGurzuInc
 
Problem Solving Skill - Bishal Sapkota - Gurzu
Problem Solving Skill - Bishal Sapkota - GurzuProblem Solving Skill - Bishal Sapkota - Gurzu
Problem Solving Skill - Bishal Sapkota - GurzuGurzuInc
 
My experience with Mobile Testing - Asmita Poudel - Gurzu
My experience with Mobile Testing - Asmita Poudel - GurzuMy experience with Mobile Testing - Asmita Poudel - Gurzu
My experience with Mobile Testing - Asmita Poudel - GurzuGurzuInc
 
Upgrading Services _ Ashraya Tuldhar _ Knowledge ketchup.pptx
Upgrading Services _ Ashraya Tuldhar _ Knowledge ketchup.pptxUpgrading Services _ Ashraya Tuldhar _ Knowledge ketchup.pptx
Upgrading Services _ Ashraya Tuldhar _ Knowledge ketchup.pptxGurzuInc
 
The real definition of done (1).pptx.pdf
The real definition of done (1).pptx.pdfThe real definition of done (1).pptx.pdf
The real definition of done (1).pptx.pdfGurzuInc
 
Fantastic Blogs and How to Write Them | Alaka Acharya.pptx
Fantastic Blogs and How to Write Them | Alaka Acharya.pptxFantastic Blogs and How to Write Them | Alaka Acharya.pptx
Fantastic Blogs and How to Write Them | Alaka Acharya.pptxGurzuInc
 
The power of saying no | Abinash Bhattarai | Gurzu.pdf
The power of saying no | Abinash Bhattarai | Gurzu.pdfThe power of saying no | Abinash Bhattarai | Gurzu.pdf
The power of saying no | Abinash Bhattarai | Gurzu.pdfGurzuInc
 
DDOS Attack - Gurzu Nepal
DDOS Attack - Gurzu NepalDDOS Attack - Gurzu Nepal
DDOS Attack - Gurzu NepalGurzuInc
 
Automation Testing - G1 conference Ch13.pptx
Automation Testing - G1 conference Ch13.pptxAutomation Testing - G1 conference Ch13.pptx
Automation Testing - G1 conference Ch13.pptxGurzuInc
 
CSS 101 - G1 conference Gurzu.pptx
CSS 101 - G1 conference Gurzu.pptxCSS 101 - G1 conference Gurzu.pptx
CSS 101 - G1 conference Gurzu.pptxGurzuInc
 
Discussion Regarding benefits on taxes on income from employment.pptx
Discussion Regarding benefits on taxes on income from employment.pptxDiscussion Regarding benefits on taxes on income from employment.pptx
Discussion Regarding benefits on taxes on income from employment.pptxGurzuInc
 
How not to Model Data - G1 conference.pptx
How not to Model Data - G1 conference.pptxHow not to Model Data - G1 conference.pptx
How not to Model Data - G1 conference.pptxGurzuInc
 
RTM and Test Closure Report Gurzu Inc.pptx
RTM and Test Closure Report Gurzu Inc.pptxRTM and Test Closure Report Gurzu Inc.pptx
RTM and Test Closure Report Gurzu Inc.pptxGurzuInc
 
API Testing.pptx
API Testing.pptxAPI Testing.pptx
API Testing.pptxGurzuInc
 
Building CI_CD for Mobile Development.pptx
Building CI_CD for Mobile Development.pptxBuilding CI_CD for Mobile Development.pptx
Building CI_CD for Mobile Development.pptxGurzuInc
 

More from GurzuInc (18)

Power of documentation | Aarati Shah | Gurzu.pdf
Power of documentation | Aarati Shah | Gurzu.pdfPower of documentation | Aarati Shah | Gurzu.pdf
Power of documentation | Aarati Shah | Gurzu.pdf
 
The Art of Refactoring | Asmit Ghimire | Gurzu.pdf
The Art of Refactoring | Asmit Ghimire | Gurzu.pdfThe Art of Refactoring | Asmit Ghimire | Gurzu.pdf
The Art of Refactoring | Asmit Ghimire | Gurzu.pdf
 
I'm Programmer _ Ganesh Kunwar _ Gurzu.pdf
I'm Programmer _ Ganesh Kunwar _ Gurzu.pdfI'm Programmer _ Ganesh Kunwar _ Gurzu.pdf
I'm Programmer _ Ganesh Kunwar _ Gurzu.pdf
 
Obtaining Your Tax Clearance Certificate_ A Quick Guide | Deepak Rai | Gurzu.pdf
Obtaining Your Tax Clearance Certificate_ A Quick Guide | Deepak Rai | Gurzu.pdfObtaining Your Tax Clearance Certificate_ A Quick Guide | Deepak Rai | Gurzu.pdf
Obtaining Your Tax Clearance Certificate_ A Quick Guide | Deepak Rai | Gurzu.pdf
 
Problem Solving Skill - Bishal Sapkota - Gurzu
Problem Solving Skill - Bishal Sapkota - GurzuProblem Solving Skill - Bishal Sapkota - Gurzu
Problem Solving Skill - Bishal Sapkota - Gurzu
 
My experience with Mobile Testing - Asmita Poudel - Gurzu
My experience with Mobile Testing - Asmita Poudel - GurzuMy experience with Mobile Testing - Asmita Poudel - Gurzu
My experience with Mobile Testing - Asmita Poudel - Gurzu
 
Upgrading Services _ Ashraya Tuldhar _ Knowledge ketchup.pptx
Upgrading Services _ Ashraya Tuldhar _ Knowledge ketchup.pptxUpgrading Services _ Ashraya Tuldhar _ Knowledge ketchup.pptx
Upgrading Services _ Ashraya Tuldhar _ Knowledge ketchup.pptx
 
The real definition of done (1).pptx.pdf
The real definition of done (1).pptx.pdfThe real definition of done (1).pptx.pdf
The real definition of done (1).pptx.pdf
 
Fantastic Blogs and How to Write Them | Alaka Acharya.pptx
Fantastic Blogs and How to Write Them | Alaka Acharya.pptxFantastic Blogs and How to Write Them | Alaka Acharya.pptx
Fantastic Blogs and How to Write Them | Alaka Acharya.pptx
 
The power of saying no | Abinash Bhattarai | Gurzu.pdf
The power of saying no | Abinash Bhattarai | Gurzu.pdfThe power of saying no | Abinash Bhattarai | Gurzu.pdf
The power of saying no | Abinash Bhattarai | Gurzu.pdf
 
DDOS Attack - Gurzu Nepal
DDOS Attack - Gurzu NepalDDOS Attack - Gurzu Nepal
DDOS Attack - Gurzu Nepal
 
Automation Testing - G1 conference Ch13.pptx
Automation Testing - G1 conference Ch13.pptxAutomation Testing - G1 conference Ch13.pptx
Automation Testing - G1 conference Ch13.pptx
 
CSS 101 - G1 conference Gurzu.pptx
CSS 101 - G1 conference Gurzu.pptxCSS 101 - G1 conference Gurzu.pptx
CSS 101 - G1 conference Gurzu.pptx
 
Discussion Regarding benefits on taxes on income from employment.pptx
Discussion Regarding benefits on taxes on income from employment.pptxDiscussion Regarding benefits on taxes on income from employment.pptx
Discussion Regarding benefits on taxes on income from employment.pptx
 
How not to Model Data - G1 conference.pptx
How not to Model Data - G1 conference.pptxHow not to Model Data - G1 conference.pptx
How not to Model Data - G1 conference.pptx
 
RTM and Test Closure Report Gurzu Inc.pptx
RTM and Test Closure Report Gurzu Inc.pptxRTM and Test Closure Report Gurzu Inc.pptx
RTM and Test Closure Report Gurzu Inc.pptx
 
API Testing.pptx
API Testing.pptxAPI Testing.pptx
API Testing.pptx
 
Building CI_CD for Mobile Development.pptx
Building CI_CD for Mobile Development.pptxBuilding CI_CD for Mobile Development.pptx
Building CI_CD for Mobile Development.pptx
 

Recently uploaded

Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Flutter Agency
 
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024MulesoftMunichMeetup
 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletAndrea Goulet
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypseTomasz Kowalczewski
 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit MilanNeo4j
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConNatan Silnitsky
 
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...Neo4j
 
Transformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksTransformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksJinanKordab
 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024SimonedeGijt
 
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfryanfarris8
 
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio, Inc.
 
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with GraphGraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with GraphNeo4j
 
Test Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfTest Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfkalichargn70th171
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Henry Schreiner
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAShane Coughlan
 

Recently uploaded (20)

Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
 
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
 
Abortion Pill Prices Jane Furse ](+27832195400*)[🏥Women's Abortion Clinic in ...
Abortion Pill Prices Jane Furse ](+27832195400*)[🏥Women's Abortion Clinic in ...Abortion Pill Prices Jane Furse ](+27832195400*)[🏥Women's Abortion Clinic in ...
Abortion Pill Prices Jane Furse ](+27832195400*)[🏥Women's Abortion Clinic in ...
 
Abortion Clinic in Bloemfontein [(+27832195400*)]🏥Safe Abortion Pills In Bloe...
Abortion Clinic in Bloemfontein [(+27832195400*)]🏥Safe Abortion Pills In Bloe...Abortion Clinic in Bloemfontein [(+27832195400*)]🏥Safe Abortion Pills In Bloe...
Abortion Clinic in Bloemfontein [(+27832195400*)]🏥Safe Abortion Pills In Bloe...
 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea Goulet
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeCon
 
Abortion Pill Prices Rustenburg [(+27832195400*)] 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Rustenburg [(+27832195400*)] 🏥 Women's Abortion Clinic i...Abortion Pill Prices Rustenburg [(+27832195400*)] 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Rustenburg [(+27832195400*)] 🏥 Women's Abortion Clinic i...
 
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
 
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
 
Transformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksTransformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with Links
 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
 
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
 
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
 
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with GraphGraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
 
Test Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfTest Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdf
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
Abortion Clinic in Midrand [(+27832195400*)]🏥Safe Abortion Pills In Midrand |...
Abortion Clinic in Midrand [(+27832195400*)]🏥Safe Abortion Pills In Midrand |...Abortion Clinic in Midrand [(+27832195400*)]🏥Safe Abortion Pills In Midrand |...
Abortion Clinic in Midrand [(+27832195400*)]🏥Safe Abortion Pills In Midrand |...
 

Hotwire and Turbo - Knowledge Ketchup - Prajit Bhandari.pdf

  • 1. Hotwire and Turbo In Ruby on Rails 7 Prajit Bhandari
  • 2. Introduction to Hotwire ● HTML over the Wire (idea of sending HTML instead of data) ● Default front-end framework for Ruby on Rails application ● Combination of Stimulus , Turbo , and Turbo Drive ● Introduced in Ruby on Rails 6 as optional feature ● Included by default in Ruby on Rails 7 ● Goal: SPA(Single Page Application) and application speed up
  • 3.
  • 4. Installing Turbo in Rails application ● GemFile gem 'turbo-rails' gem 'stimulus-rails' ● execute bundle install in terminal ● Application.js import "@hotwired/turbo-rails" import "./controllers"
  • 5. Benefits of using Hotwire ● Reduce server requests: Use Turbo Streams to update parts of a page without a full server request. ● Eliminate page reloads: Use Turbo Drive to load linked pages in the background and swap out only the content that needs to be changed. ● Improve perceived performance: Use Stimulus.js to progressively enhance the user interface, making it feel faster and more responsive. ● Optimize network usage: Use Turbo Streams to send only the data that needs to be updated on the page, reducing the amount of data transferred between server and client. ● Reduce development time: Use Hotwire's cohesive set of tools to avoid learning and integrating multiple third-party libraries. ● Security: CSRF and XSS attack prevention by default.
  • 6. Turbo in Hotwire ● JS library built on top of Hotwire and enables real-time updates ● Comprises of Turbo Frame and Turbo Stream ● SPA without having to write much custom JS ● Focuses on providing high-performance ● Low-overhead way to build web apps
  • 7. Turbo Frame in Turbo ● Independent pieces of a web page that can be appended, prepended, replaced, or removed without a complete page refresh. ● All clicks on links and form submissions are now AJAX requests by default ● Syntax: <%= turbo_frame_tag ‘frame_name’ , target: ‘target_type’ , src: ‘url’ do %> #code blocks <% end %> ● Turbo Frame name are usually specified with dom_id(@instance) ● Html elements wrapped under a turbo-frame-tag references the same tag name in the redirected url. ● Turbo Frame holds “src”a data-property which contains the url of an endpoint to fetch content from the respective url
  • 8.
  • 9. Turbo Frame Type ● Eager loaded Frame: - Works like the basic frame, but the content is loaded from a remote src first. - <% turbo_frame_tag src="/messages" %> - # Content will be replaced when /messages has been loaded. - <% end %> ● Lazy loaded Frame: - Like an eager-loaded frame, but the content is not loaded from src until the frame is visible. - <% turbo_frame_tag src="/messages" loading = lazy %> - #Content will be replaced when the frame becomes visible and /messages has been loaded. - <% end %>
  • 10. Turbo Frame Target ● _self: The linked document will open in the same frame or window as the current document. ● _parent: The linked document will open in the parent frame of the current frame or window. If there is no parent, it behaves like _self. ● _blank: The linked document will open in a new, unnamed window or tab. ● _top: The linked document will open in the top-level frame or window. If there are nested frames, all frames will be replaced with the linked document.
  • 11.
  • 12. Nested Turbo Frame ● Need to render a turbo frame inside another turbo frame. ● Allows for more faster loading times. ● Multiple parts of a page can be updated independently, rather than having to reload the entire page. ● <%= turbo_frame_tag nested_dom_id(instance1, instance2) % do > ● <%# content %> ● <% end %>
  • 13.
  • 14. Turbo Stream in Turbo ● Forms in Rails 7 are now submitted with the TURBO_STREAM format ● View file is implemented as <file/endpoint name>.turbo_stream.erb ● Turbo Stream format is mechanism for updating parts of a webpage without requiring a full page reload. ● This allows for faster and more responsive user experiences, as only the necessary components of the page are updated.
  • 15. Turbo Drive ● With turbo drive, data-turbo=’true’ is enabled on a turbo frame ● Extension of Turbo that allows for real-time updates to web pages without the need for a full page refresh. ● Intercepts form submissions and link clicks, and sending the data via a streaming connection to the server, which then updates the page without the need for a full page refresh ● Adding data-turbo=’false’ data attribute on the HTML element disables turbo
  • 16. A Basic Flow of Hotwire and Turbo
  • 17. Stimulus ● JS framework for adding behavior to your HTML. ● lightweight and efficient, with a small code footprint and minimal performance overhead. ● A user-initiated event that triggers a state change in the application ● Allows you to add JavaScript to your HTML by using "controllers" that can respond to events on the page
  • 18. How does Stimulus JS work? ● Intercepts events: button clicks, form submissions, and link clicks ● Can be handled by the Hotwire JavaScript library, which listens for events on the page and sends an HTTP request to the server. ● The server then responds with the updated HTML and JavaScript necessary to update the state of the application, which is then rendered in the browser. ● Uses a declarative approach: <button data-controller="controller_name" data-#{controller-name}–#{attribute}-value=”value” data-action="click->controller_name#method_name">Greet</button>
  • 19. Boiler Plate of Stimulus js import { Controller } from "stimulus" export default class extends Controller { static values = { name: String} initialize() { console.log("Controller initialized once for default values") } connect() { console.log("Controller connected") } method_name() { const name = this.nameValue || "World" console.log(`Hello, ${name}!`) } }
  • 20. Index.js ● import { application } from './application' ● import DemoController from './demo_controller.js' ● application.register('demo', DemoController) ● Note: This controller files should be placed inside javascript/controller dir
  • 21. BEM Methodology ● Block Element Modifier ● A CSS architecture preferred in Hotwire and Turbo ● Provides modularity with no overlapping issues with the element ● BEM is a natural fit with Stimulus to add behavior to HTML elements. ● Example: