Slide 1

Slide 1 text

JS for Rails Developers (is jQuery OK?) Bruno Cunha, EarlyShares

Slide 2

Slide 2 text

How’s your JavaScript?

Slide 3

Slide 3 text

Agenda • Why? • AJAX • Unobtrusive JavaScript • Rails Helpers • Server-side Concerns • Turbolinks • Final Thoughts

Slide 4

Slide 4 text

Why? JavaScript • Gut check • The best way • Client satisfaction jQuery • Easy

Slide 5

Slide 5 text

AJAX Traditional Request-Response cycle • Client fetches full page and assets • Assemble everything together Asynchronous JavaScript and XML • Client fetches and renders data via JavaScript • Only update changed parts

Slide 6

Slide 6 text

Unobtrusive JavaScript Separation of concerns • Avoid mixing presentation, layout, and behavior • Use data attributes to store private data

Slide 7

Slide 7 text

Rails Helpers Form Options • Remote submits request using AJAX Link and Button Options • Also accept remote • Method changes request type • Confirm prompts the user after the request is made • Disable-with prevents multiple form submissions

Slide 8

Slide 8 text

Server-side Concerns Serve appropriate response formats • Default is HTML • Options are JS, JSON, and XML

Slide 9

Slide 9 text

Turbolinks • Makes apps faster by persisting assets and only rendering body changes • Other features include transition cache, opt-out, and progress bar • Uses custom page events, use jquery-turbolinks • 3rd-party plugins are problematic

Slide 10

Slide 10 text

Final Thoughts User experience simply matters • Performance is easy and good Further Reading • Slack’s $2.8 Billion Dollar Secret Sauce - https://medium.com/@awilkinson/slack- s-2-8-billion-dollar-secret-sauce-5c5ec7117908 • Working with JavaScript in Rails - http://guides.rubyonrails.org/ working_with_javascript_in_rails.html • A Tour of Rails’ jQuery UJS - https://robots.thoughtbot.com/a-tour-of-rails-jquery-ujs • How I Use Turbolinks - https://pooreffort.com/blog/how-i-use-turbolinks/

Slide 11

Slide 11 text

Thank You! @bruncun