Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rails Frontend: 2016 edition.

Rails Frontend: 2016 edition.

Slides from talk about enhancements in Rails Frontend.

vipulnsward

June 24, 2016
Tweet

More Decks by vipulnsward

Other Decks in Programming

Transcript

  1. manifest.js config.assets.precompile = [“manifest.js”] // app/assets/config/manifest.js //= link_tree ../images
 //=

    link_directory ../stylesheets .css //= link application.css
 //= link advertising.css
 //= link payment.css
 //= link application.js

  2. folders as modules //= require_tree . foo/jquery-ui.js and foo/jquery.min.js Now:

    //= require foo.js # foo/index.js //= require foo.min.js
 //= require foo-ui.js

  3. ES2016! 1. Arrows and Lexical This 2. Classes 3. Enhanced

    Object Literals 4. Template Strings 5. Destructuring 6. Default + Rest + Spread 7. Let + Const 8. Iterators + For..Of 9. Symbols, etc
  4. $ curl -i http://localhost:3000/items/1
 
 HTTP/1.1 200 OK
 X-Frame-Options: SAMEORIGIN


    X-Xss-Protection: 1; mode=block
 X-Content-Type-Options: nosniff
 Etag: "618bbc92e2d35ea1945008b42799b0e7"
 Last-Modified: Sat, 30 Jan 2016 08:02:12 GMT
 Content-Type: text/html; charset=utf-8
 Cache-Control: max-age=0, private, must-revalidate
 X-Request-Id: 98359119-14ae-4e4e-8174-708abbc3fd4b
 X-Runtime: 0.412232
 Server: WEBrick/1.3.1 (Ruby/2.2.2/2015-04-13)
 Date: Fri, 04 Mar 2016 10:50:38 GMT
 Content-Length: 1014
 Connection: Keep-Alive Etag
  5. $ curl -i -H 'If-None-Match: "618bbc92e2d35ea1945008b42799b0e7"' http:// localhost:3000/items/1
 
 HTTP/1.1

    304 Not Modified
 X-Frame-Options: SAMEORIGIN
 X-Xss-Protection: 1; mode=block
 X-Content-Type-Options: nosniff
 Etag: "618bbc92e2d35ea1945008b42799b0e7"
 Last-Modified: Sat, 30 Jan 2016 08:02:12 GMT
 Cache-Control: max-age=0, private, must-revalidate
 X-Request-Id: e4447f82-b96c-4482-a5ff-4f5003910c18
 X-Runtime: 0.012878
 Server: WEBrick/1.3.1 (Ruby/2.2.2/2015-04-13)
 Date: Fri, 04 Mar 2016 10:51:22 GMT
 Connection: Keep-Alive Etag
  6. # app/controllers/home_controller.rb
 class HomeController < ApplicationController
 def index
 render
 end


    end
 
 # app/views/home/index.html.erb
 <h1>Welcome</h1> http_cache_forever
  7. Processing by HomeController#index as HTML
 Rendered home/index.html.erb within layouts/ application

    (1.3ms)
 Completed 200 OK in 224ms (Views: 212.4ms | ActiveRecord: 0.0ms)
 
 And so on for every request for this action.
 http_cache_forever
  8. # app/controllers/home_controller.rb
 class HomeController < ApplicationController
 def index
 http_cache_forever(public: true)

    {}
 end
 end
 
 # OR
 class HomeController < ApplicationController
 def index
 http_cache_forever(public: true) do
 render
 end
 end
 end
 
 
 # app/views/home/index.html.erb
 <h1>Welcome</h1> http_cache_forever
  9. # When request is made for the first time.
 


    Processing by HomeController#index as HTML
 Rendered home/index.html.erb within layouts/ application (1.3ms)
 Completed 200 OK in 224ms (Views: 212.4ms | ActiveRecord: 0.0ms)
 
 # For consecutive requests for the same page
 
 Processing by HomeController#index as HTML
 Completed 304 Not Modified in 2ms (ActiveRecord: 0.0ms) http_cache_forever
  10. # production.rb
 
 config.public_file_server.headers = {
 'Cache-Control' => 'public, s-maxage=31536000,

    maxage=15552000',
 'Expires' => "#{1.year.from_now.to_formatted_s(:rfc822)}"
 } Public Asset Header
  11. 1.Page Caching 2.Action Caching 3.Fragment Caching 4.Russian Doll Caching 5.Low-Level

    Caching 6.SQL Caching http://edgeguides.rubyonrails.org/ caching_with_rails.html Caching
  12. # index.html.erb
 <%= render partial: 'todo', collection: @todos %>
 


    # _todo.html.erb
 <% cache todo do %>
 <%= todo.name %>
 <% end %>
 Partial rendering from cache
  13. # index.html.erb
 <%= render partial: 'todo', collection: @todos, cached: true

    %>
 
 # _todo.html.erb
 <% cache todo do %>
 <%= todo.name %>
 <% end %> multi_fetch_fragments
  14. <body>
 
 <% cache 'signup-text' do %>
 <h1>Welcome to <%=

    @company.name %></h1>
 <p>You have successfully signed up to <%= @company.name %>, Your username is:
 <% end %>
 
 <%= @user.login %>.
 <br />
 </p>
 
 <%= render :partial => 'footer' %>
 
 </body> ActionMailer Fragment Caching
  15. Cache digest for app/views/user_mailer/_footer.erb: 7313427d26cc1f701b1e0212498cee38
 Cache digest for app/views/user_mailer/welcome_email.html.erb: 30efff0173fd5f29a88ffe79a9eab617


    Rendered user_mailer/_footer.erb (0.3ms)
 Rendered user_mailer/welcome_email.html.erb (26.1ms)
 Cache digest for app/views/user_mailer/welcome_email.text.erb: 77f41fe6159c5736ab2026a44bc8de55
 Rendered user_mailer/welcome_email.text.erb (0.2ms)
 UserMailer#welcome_email: processed outbound mail in 190.3ms ActionMailer Fragment Caching
  16. @users = User.where(city: 'miami') 1.The query statement doesn’t change. If

    we change city name from “Miami” to “Boston” then result might change. 2.No record is deleted. 3.No record is added. Caching result sets and collection
  17. 1.Placement of JS/CSS imports 2.Font imports 3.Analytics tags 4.Proper viewports

    5.responsive 6.Inlining resources, css/js, etc PageSpeed
  18. <!doctype html>
 <html class="" lang="">
 <head>
 … <title>
 <%= @page_title

    || default_page_title %> | BigBinary
 </title>
 <%= stylesheet_link_tag "application.css", 'data-turbolinks- track' => true %>
 …
 <%= csrf_meta_tags %>
 </head>
 <body>
 <%= yield %>
 <script src="https://use.typekit.net/drp7ohd.js"></script>
 <script>try{Typekit.load({ async: true });}catch(e){}</script>
 
 <%= javascript_include_tag "application.js", media: 'all', 'data-turbolinks-track' => true, async: true, defer: true %>
 
 </body>
 </html>