SlideShare a Scribd company logo
1 of 45
Rails 3 Asset Pipeline
Damian Galarza
http://www.damiangalarza.com
          @dgalarza
http://www.qfive.com
    @qfivesports
What is the Asset
         Pipeline?
• Build system for your static assets
  • Javascript
  • CSS
  • Images
What is the Asset
         Pipeline?


• Sass and Coffeescript support by default
• Minifies and concatenates resources
Defaults
source 'https://rubygems.org'

gem 'rails', '3.2.5'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for
more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'
Storing Assets
app/
	 asssets/
	 	 javascripts/
	 	 stylesheets/
	 	 images/
	 	
vendor/
	 assets/
	 	 javascripts/
	 	 stylesheets/
	 	
public/
	 assets/
app/
	 asssets/
	 	 javascripts/

 
 
 application.js

	 	 stylesheets/
	 	 	 application.css

	 	 images/
	 	 	 rails.png
vendor/
	 assets/

	 	 javascripts/
	 	 	 jquery.masonry.js
	 	 	 tagit.js

	 	 stylesheets/
	 	 	 tagit.css
public/
	 assets/
	 	 application-e4b51606cd77f.js
	 	 rails-e4b51606cd77fda26.png
	 	 application-e4b51606cd77fd.css
Sprockets
https://github.com/sstephenson/
            sprockets
Sprockets
                 Javascript

//=   require core.js
//=   require jquery.infinitescroll
//=   require jquery.masonry.min
//=   require jquery.backstretch.min
//=   require bootstrap-alert
//=   require bootstrap-dropdown
//=   require bootstrap-modal
//=   require bootstrap-tab
//=   require_self

                                 application.js
Sprockets
                  CSS
/**
*= require   "bootstrap_and_overrides";
*= require   'sprites';
*= require   'layout';
*= require   'typography';
*= require   'admin';
*= require   'clubs';
*= require   'posts';
*= require   'sharing';
*= require   'tags';
*= require   'topics';
*= require   'users';
*= require   'welcome';
*= require   'responsive';
*= require   'landing_pages';
*/
                                 application.css
Sprockets


  = stylesheet_link_tag "application"

= javascript_include_tag "application"
Sprockets
Sprockets
Sprockets


application-7e817f92bce80b73114a04de53d57b80.js
Cache-Control

HTTP header to max-age=31536000


           (1 year)
JS Minifcation



• Handled by uglifier gem by default
Using a CDN


config.action_controller.asset_host = "http://yourhost.cloudfront.net"
Referencing Assets
Sprockets Precompile


• ERB files:
 • layout.js.erb
 • layout.js.coffee.erb
Referencing Assets


$.backstretch('<%= asset_path("bg-image-field-large.jpg") %>');
Referencing Assets


$.backstretch("/assets/field-at-night-bw-noise-4cdc7135443f06bdd3857a56a4bf7521.jpg")
Referencing Assets



• sass-rails rewrite of helpers:
  • image-url / image - path
Referencing Assets


#mobile-container {
! background: image-url('tour-program-mobile.jpg') no-repeat;
}
Referencing Assets


#mobile-container {
! background: url("/assets/tour-program-mobile-bdf25b7b3d9971aa362eeb90bf6b4bb6.jpg");
}
Precompiling
bundle exec rake assets:precompile
Capistrano


load 'deploy/assets'
Using Compass
gem 'compass-rails'
Use @import
/**
*= require   "bootstrap_and_overrides";
*= require   'sprites';
*= require   'layout';
*= require   'typography';
*= require   'admin';
*= require   'clubs';
*= require   'posts';
*= require   'sharing';
*= require   'tags';
*= require   'topics';
*= require   'users';
*= require   'welcome';
*= require   'responsive';
*= require   'landing_pages';
*/
@import   "bootstrap_and_overrides";
@import   'sprites';
@import   'layout';
@import   'typography';
@import   'admin';
@import   'clubs';
@import   'posts';
@import   'sharing';
@import   'tags';
@import   'topics';
@import   'users';
@import   'welcome';
@import   'responsive';
@import   'landing_pages';
Organize
Not everything belongs
   in application.js
config.assets.precompile += %w{profile.js mobile_application.js}
Make use of
dependency building
core.js
//=   require jquery
//=   require jquery.ui.autocomplete
//=   require jquery_ujs
//=   require tagit
//=   require underscore
//=   require jquery.infinitescroll
//=   require jquery.backstretch.min
//=   require bootstrap-transition
//=   require bootstrap-collapse
//=   require bootstrap-tab
//=   require handlebars-1.0.0.beta.6.js
//=   require jwplayer.js
//=   require relative-date
//=   require 'facebook'
//=   require 'comments'
//=   require 'layout'
//=   require 'posts'
//=   require 'sharing'
//=   require 'users'
//=   require_self
application.js
//=   require core.js
//=   require jquery.effects.blind
//=   require jquery.infinitescroll
//=   require jquery.masonry.min
//=   require jquery.backstretch.min
//=   require jquery.preview.full
//=   require jquery.truncator
//=   require jquery.panda-uploader.js
//=   require bootstrap-alert
//=   require bootstrap-dropdown
//=   require bootstrap-modal
//=   require bootstrap-tab
//=   require gmaps4rails/googlemaps
//=   require 'sign-in'
//=   require_self
mobile_application.js


  // Optimized mobile application js

  //= require core.js
  //= require mobile_modals.js
Dependencies

#= require_tree ./posts

$ ->
  Post.embedlyPreview('#post_link_url')
  Post.embedlyPreview('#post_video_url')
  replaceTimesWithRelativeStrings()
  setupTagging()
  setupPanda()
  loadVideo()
  setupVideoPostOptions()
  setupShareLinks()
  setupInfiniteScroll()




                                           posts.js
Questions?

More Related Content

What's hot

CodeFest 2014. Пухальский И. — Отзывчивые кроссплатформенные веб-приложения
CodeFest 2014. Пухальский И. — Отзывчивые кроссплатформенные веб-приложенияCodeFest 2014. Пухальский И. — Отзывчивые кроссплатформенные веб-приложения
CodeFest 2014. Пухальский И. — Отзывчивые кроссплатформенные веб-приложения
CodeFest
 
Integrating Browserify with Sprockets
Integrating Browserify with SprocketsIntegrating Browserify with Sprockets
Integrating Browserify with Sprockets
Spike Brehm
 
jQtouch, Building Awesome Webapps
jQtouch, Building Awesome WebappsjQtouch, Building Awesome Webapps
jQtouch, Building Awesome Webapps
Home
 

What's hot (20)

Workshop 21: React Router
Workshop 21: React RouterWorkshop 21: React Router
Workshop 21: React Router
 
Sails.js - Overview
Sails.js - OverviewSails.js - Overview
Sails.js - Overview
 
Brunch With Coffee
Brunch With CoffeeBrunch With Coffee
Brunch With Coffee
 
Ruby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter BootstrapRuby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter Bootstrap
 
CodeFest 2014. Пухальский И. — Отзывчивые кроссплатформенные веб-приложения
CodeFest 2014. Пухальский И. — Отзывчивые кроссплатформенные веб-приложенияCodeFest 2014. Пухальский И. — Отзывчивые кроссплатформенные веб-приложения
CodeFest 2014. Пухальский И. — Отзывчивые кроссплатформенные веб-приложения
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJS
 
Introduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersIntroduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress Developers
 
JavaScript Dependencies, Modules & Browserify
JavaScript Dependencies, Modules & BrowserifyJavaScript Dependencies, Modules & Browserify
JavaScript Dependencies, Modules & Browserify
 
Integrating Browserify with Sprockets
Integrating Browserify with SprocketsIntegrating Browserify with Sprockets
Integrating Browserify with Sprockets
 
SPA using Rails & Backbone
SPA using Rails & BackboneSPA using Rails & Backbone
SPA using Rails & Backbone
 
RequireJS
RequireJSRequireJS
RequireJS
 
iPhone Appleless Apps
iPhone Appleless AppsiPhone Appleless Apps
iPhone Appleless Apps
 
Using Angular with Rails
Using Angular with RailsUsing Angular with Rails
Using Angular with Rails
 
jQtouch, Building Awesome Webapps
jQtouch, Building Awesome WebappsjQtouch, Building Awesome Webapps
jQtouch, Building Awesome Webapps
 
uRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.orguRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.org
 
Webapps without the web
Webapps without the webWebapps without the web
Webapps without the web
 
Digital Ocean Presentation - Ruby Dev Stackup - The Flatiron School
Digital Ocean Presentation - Ruby Dev Stackup - The Flatiron School Digital Ocean Presentation - Ruby Dev Stackup - The Flatiron School
Digital Ocean Presentation - Ruby Dev Stackup - The Flatiron School
 
WordPress as the Backbone(.js)
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)
 
Require js
Require jsRequire js
Require js
 
Arquitetura de Front-end em Aplicações de Larga Escala
Arquitetura de Front-end em Aplicações de Larga EscalaArquitetura de Front-end em Aplicações de Larga Escala
Arquitetura de Front-end em Aplicações de Larga Escala
 

Viewers also liked (14)

Integrating omic approaches to investigate the gut microbiota, School of Bios...
Integrating omic approaches to investigate the gut microbiota, School of Bios...Integrating omic approaches to investigate the gut microbiota, School of Bios...
Integrating omic approaches to investigate the gut microbiota, School of Bios...
 
T&d system measurement t&d kpi panel
T&d system measurement t&d kpi panelT&d system measurement t&d kpi panel
T&d system measurement t&d kpi panel
 
יום מושלם מצגת
יום מושלם מצגתיום מושלם מצגת
יום מושלם מצגת
 
Latiff
LatiffLatiff
Latiff
 
321 unit 16 success
321 unit 16 success321 unit 16 success
321 unit 16 success
 
Aug 31 2012 WEBQUEST
Aug 31 2012 WEBQUESTAug 31 2012 WEBQUEST
Aug 31 2012 WEBQUEST
 
EXP ENG Unit 9
EXP ENG Unit 9 EXP ENG Unit 9
EXP ENG Unit 9
 
Aucfan Presentation @Redherring Asia 2014 Presentation
Aucfan Presentation @Redherring Asia 2014 PresentationAucfan Presentation @Redherring Asia 2014 Presentation
Aucfan Presentation @Redherring Asia 2014 Presentation
 
Rpp
RppRpp
Rpp
 
AND Isitallaboutwhoyouknow - future directions report
AND Isitallaboutwhoyouknow - future directions reportAND Isitallaboutwhoyouknow - future directions report
AND Isitallaboutwhoyouknow - future directions report
 
Mapování zdrojů univerzity - Kamil Krč
Mapování zdrojů univerzity - Kamil KrčMapování zdrojů univerzity - Kamil Krč
Mapování zdrojů univerzity - Kamil Krč
 
321 unit 2 project
321 unit 2 project321 unit 2 project
321 unit 2 project
 
Ana and mia
Ana and mia Ana and mia
Ana and mia
 
Future Educator Association FEA Advisor Update Session
Future Educator Association FEA Advisor Update Session Future Educator Association FEA Advisor Update Session
Future Educator Association FEA Advisor Update Session
 

Similar to Rails3 asset-pipeline

Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011
Chris Alfano
 
"Your script just killed my site" by Steve Souders
"Your script just killed my site" by Steve Souders"Your script just killed my site" by Steve Souders
"Your script just killed my site" by Steve Souders
Dmitry Makarchuk
 
20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev
Frank Rousseau
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
Yehuda Katz
 

Similar to Rails3 asset-pipeline (20)

Fisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com RubyFisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
 
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com RubyConsegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
 
Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011
 
"Your script just killed my site" by Steve Souders
"Your script just killed my site" by Steve Souders"Your script just killed my site" by Steve Souders
"Your script just killed my site" by Steve Souders
 
20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev
 
RoR 101: Session 6
RoR 101: Session 6RoR 101: Session 6
RoR 101: Session 6
 
JavaScript performance patterns
JavaScript performance patternsJavaScript performance patterns
JavaScript performance patterns
 
Less & RequireJS - Frontend Development in Magento 2
Less & RequireJS - Frontend Development in Magento 2Less & RequireJS - Frontend Development in Magento 2
Less & RequireJS - Frontend Development in Magento 2
 
How to replace rails asset pipeline with webpack?
How to replace rails asset pipeline with webpack?How to replace rails asset pipeline with webpack?
How to replace rails asset pipeline with webpack?
 
Beyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance JavascriptBeyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance Javascript
 
Rich Portlet Development in uPortal
Rich Portlet Development in uPortalRich Portlet Development in uPortal
Rich Portlet Development in uPortal
 
Build Better Responsive websites. Hrvoje Jurišić
Build Better Responsive websites. Hrvoje JurišićBuild Better Responsive websites. Hrvoje Jurišić
Build Better Responsive websites. Hrvoje Jurišić
 
The new static resources framework
The new static resources frameworkThe new static resources framework
The new static resources framework
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
 
Resource Registries: Plone Conference 2014
Resource Registries: Plone Conference 2014Resource Registries: Plone Conference 2014
Resource Registries: Plone Conference 2014
 
以Vue開發電子商務網站
架構與眉角
以Vue開發電子商務網站
架構與眉角以Vue開發電子商務網站
架構與眉角
以Vue開發電子商務網站
架構與眉角
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Node.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseNode.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash Course
 
RoR 101: Session 6
RoR 101: Session 6RoR 101: Session 6
RoR 101: Session 6
 
JavaScript Performance Patterns
JavaScript Performance PatternsJavaScript Performance Patterns
JavaScript Performance Patterns
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Rails3 asset-pipeline

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n