Rails assets pipeline
                                   @ka8725




суббота, 6 октября 12 г.
Objects

                     • Css (SaSS)
                     • Javascript (coffeescript)
                     • Images
                     • Fonts
                     • other files...

суббота, 6 октября 12 г.
Why?
                     • Compressing up to 80%




суббота, 6 октября 12 г.
Why?
                   • Caching (with digests)




суббота, 6 октября 12 г.
Assets folders

                     • app/assets/
                     • lib/assets
                     • vendor/assets


суббота, 6 октября 12 г.
Assets folder structure
                     • app/assets/ or lib/assets or
                           vendor/assets

                           • stylesheets
                           • javascripts
                           • images
                           • your own folder (for example fonts)
суббота, 6 октября 12 г.
Main files
                           file1.js


                                     included   application.js

                           file2.js




суббота, 6 октября 12 г.
application.js

                     • //= require jquery
                     • //= require jquery_ujs
                     • //= reauire_tree .


суббота, 6 октября 12 г.
Including assets to
                                  views
                     • javascript_include_tag
                     • stylesheet_include_tag
                     • image_tag
                     • asset_path

суббота, 6 октября 12 г.
Examples

                     • javascript_include_tag ‘application’
                     • stylesheet_include_tag ‘application’

                     • javascript_include_tag ‘my_file’
                    * Change config/environments/production.rb:
                      config.assets.precompile += %w(my_file.js)

суббота, 6 октября 12 г.
Gems for compressing

                     • closure
                     • uglifier (default)
                     • yui


суббота, 6 октября 12 г.
When compile?

                     • Only in production mode
                     • In development just make sure that:
                           rake assets:precompile works

                     • Always clean assets in development mode:
                           rake assets:clean



суббота, 6 октября 12 г.
Where?

                     • Production server
                     • Content Delivery Network (CDN)
                     • Just other server (your own CDN)


суббота, 6 октября 12 г.
Workflows: 1

                     • run rake assets:precompile in
                           development mode
                     • push compiled assets (/public/assets) to
                           CDN
                     • push your new code to the production
                           server



суббота, 6 октября 12 г.
Workflows: 2

                     • Push code to production server
                     • Precompile assets on the server
                     • Push assets to the CDN


суббота, 6 октября 12 г.
Production release
                                 structure
                            CDN (Content                     Production server
                           Delivery Network)




                                               Development
                                                 machine




суббота, 6 октября 12 г.
Famous CDNs


                     • Amazon S3
                     • Rackspace


суббота, 6 октября 12 г.
Tools to pushing assets
                          to CDN

                     • asset_sync (we will use it)
                     • jammit_s3
                     • others


суббота, 6 октября 12 г.
Q/A?


                     • http://github.com/ka8725
                     • http://twitter.com/@ka8725


суббота, 6 октября 12 г.

Rails 3 assets pipeline

  • 1.
    Rails assets pipeline @ka8725 суббота, 6 октября 12 г.
  • 2.
    Objects • Css (SaSS) • Javascript (coffeescript) • Images • Fonts • other files... суббота, 6 октября 12 г.
  • 3.
    Why? • Compressing up to 80% суббота, 6 октября 12 г.
  • 4.
    Why? • Caching (with digests) суббота, 6 октября 12 г.
  • 5.
    Assets folders • app/assets/ • lib/assets • vendor/assets суббота, 6 октября 12 г.
  • 6.
    Assets folder structure • app/assets/ or lib/assets or vendor/assets • stylesheets • javascripts • images • your own folder (for example fonts) суббота, 6 октября 12 г.
  • 7.
    Main files file1.js included application.js file2.js суббота, 6 октября 12 г.
  • 8.
    application.js • //= require jquery • //= require jquery_ujs • //= reauire_tree . суббота, 6 октября 12 г.
  • 9.
    Including assets to views • javascript_include_tag • stylesheet_include_tag • image_tag • asset_path суббота, 6 октября 12 г.
  • 10.
    Examples • javascript_include_tag ‘application’ • stylesheet_include_tag ‘application’ • javascript_include_tag ‘my_file’ * Change config/environments/production.rb: config.assets.precompile += %w(my_file.js) суббота, 6 октября 12 г.
  • 11.
    Gems for compressing • closure • uglifier (default) • yui суббота, 6 октября 12 г.
  • 12.
    When compile? • Only in production mode • In development just make sure that: rake assets:precompile works • Always clean assets in development mode: rake assets:clean суббота, 6 октября 12 г.
  • 13.
    Where? • Production server • Content Delivery Network (CDN) • Just other server (your own CDN) суббота, 6 октября 12 г.
  • 14.
    Workflows: 1 • run rake assets:precompile in development mode • push compiled assets (/public/assets) to CDN • push your new code to the production server суббота, 6 октября 12 г.
  • 15.
    Workflows: 2 • Push code to production server • Precompile assets on the server • Push assets to the CDN суббота, 6 октября 12 г.
  • 16.
    Production release structure CDN (Content Production server Delivery Network) Development machine суббота, 6 октября 12 г.
  • 17.
    Famous CDNs • Amazon S3 • Rackspace суббота, 6 октября 12 г.
  • 18.
    Tools to pushingassets to CDN • asset_sync (we will use it) • jammit_s3 • others суббота, 6 октября 12 г.
  • 19.
    Q/A? • http://github.com/ka8725 • http://twitter.com/@ka8725 суббота, 6 октября 12 г.