Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Turing School - Understanding the Asset Pipeline
Search
Turing School
April 11, 2017
Programming
44
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Turing School - Understanding the Asset Pipeline
Rails Asset Pipeline Lesson Slides
Turing School
April 11, 2017
Other Decks in Programming
See All in Programming
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
150
AI主導のプログラミング学習アプリを作ってみた
econanringo
0
180
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.9k
Railsバージョンを4倍にした話
optim
0
430
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
430
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
280
気持ちぃ〜角丸 Squircle
ryu1013
0
310
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
290
パスワード再設定メールのURLについて知っておこう
uyuki234
0
160
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
120
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
140
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
5.2k
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
How to build a perfect <img>
jonoalderson
1
6.1k
Unsuck your backbone
ammeep
672
58k
Technical Leadership for Architectural Decision Making
baasie
3
600
Visualization
eitanlees
153
17k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
380
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
630
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
280
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
Transcript
Understanding the Asset Pipeline It cannot be understood
1. What is the asset pipeline 2. Asset organization 3.
Asset lookup 4. Manifests 5. ActionView helpers 6. Development vs. production
The Asset Pipeline
What is the Asset Pipeline?
Main Features
1. Asset concatenation 2. Asset minification 3. Precompilation
What is fingerprinting?
global.css global-908e25f4bf641868d8683022a5b62f54.css
global.css /stylesheets/global.css?1309495796
Asset Organization
Assets Locations
1. app/assets 2. lib/assets 3. vendor/assets
Asset directories are arbitrary
app/assets/javascripts/home.js lib/assets/javascripts/moovinator.js vendor/assets/tino_cochino/slider.js vendor/assets/barbie_hair/phonebox.js
http://localhost:3000/assets/home.js http://localhost:3000/assets/moovinator.js http://localhost:3000/assets/slider.js http://localhost:3000/assets/phonebox.js
Workshop
Clone Storedom $ git clone https://github.com/turingschool- examples/storedom.git asset_pipeline
bundle & setup the database $ bundle && rake db:setup
create a texts directory $ mkdir app/assets/texts
create a hello.txt file $ touch app/assets/texts/hello.txt
start the server and visit this path http://localhost:3000/assets/hello.txt
move the hello.txt file to the javascripts folder $
mv app/assets/{texts,javascripts}/ hello.txt
visit / reload this path again http://localhost:3000/assets/hello.txt
create a hello.js file $ touch app/assets/stylesheets/hello.js
put this into hello.js Hello, is it me you are
looking for?
visit this path http://localhost:3000/assets/hello.js
Asset Lookup
Enter this in the rails console > y Rails.application.config.assets.paths
This is my load path --- - "/Users/Jorge/Dropbox/projects/classes/storedom/app/assets/images" - "/Users/Jorge/Dropbox/projects/classes/storedom/app/assets/javascripts"
- "/Users/Jorge/Dropbox/projects/classes/storedom/app/assets/stylesheets" - "/Users/Jorge/Dropbox/projects/classes/storedom/vendor/assets/javascripts" - "/Users/Jorge/Dropbox/projects/classes/storedom/vendor/assets/stylesheets" - "/Users/Jorge/.rvm/gems/ruby-2.1.3/gems/less-rails-bootstrap-3.2.0/app/assets/fonts" - "/Users/Jorge/.rvm/gems/ruby-2.1.3/gems/less-rails-bootstrap-3.2.0/app/assets/javascripts" - "/Users/Jorge/.rvm/gems/ruby-2.1.3/gems/less-rails-bootstrap-3.2.0/app/assets/stylesheets" - "/Users/Jorge/.rvm/gems/ruby-2.1.3/gems/turbolinks-2.2.2/lib/assets/javascripts" - "/Users/Jorge/.rvm/gems/ruby-2.1.3/gems/jquery-rails-3.1.1/vendor/assets/javascripts" - "/Users/Jorge/.rvm/gems/ruby-2.1.3/gems/coffee-rails-4.0.1/lib/assets/javascripts"
Adding to the Search Path
Add this line to the config/initializers/assets.rb Rails.application.config.assets.paths << Rails.root.join("app", "flash",
"assets")
create a flashy.txt file $ touch app/flash/assets/flashy.txt
put this into flashy.txt Rockin’ like 2002
visit this path http://localhost:3000/assets/flashy.txt
Workshop
1. Create an additional path. 2. Add a file with
a txt extension. 3. Put some content in it. 4. Can you find the file with your browser and display its contents?
Manifests
What are manifests?
Let’s look at the application.js
• // require_tree • // require_directory . • Define the
files manually
//= require jquery //= require jquery_ujs //= require twitter/bootstrap //=
require turbolinks //= require_tree .
Manifest Directives
• require • include • require_self • require_directory • require_tree
• depend_on • stub
A quick note on SASS / SCSS
Use @import instead of require
ActionView Helpers
<%= stylesheet_link_tag "application", :media => "all" %> <%= javascript_include_tag "application"
%>
audio_path("horse.wav") # /audios/horse.wav audio_tag("sound") # <audio src="/audios/sound"/> font_path("font.ttf") # /fonts/font.ttf
image_path("edit.png") # "/images/edit.png" image_tag("dog.png") # <img src="/images/dog.png" alt="Dog"/> video_path("hd.avi") # /videos/hd.avi video_tag("trailer.ogg") # <video src="/videos/trailer.ogg"/>
Development vs. Production
Eliminate all of your production whoas with this ONE EASY
TRICK
Debugging Assets
Open config/environments/development.rb config.assets.debug = true
Precompiling Assets
Your assets have to be either required in your asset
pipeline or precompiled
In app/assets/stylesheets/application.css // = require_self // = require 'site'
In config/initializers/assets.rb config.assets.precompile += %w( site.css )
What happens when we precompile?
1. Rails copies all the assets into public/assets 2.
Rails then creates an application.js and application.css by reading the manifests 3. When using config.assets.precompile, the file extension matters.
Recap
1. What is the asset pipeline 2. Asset organization 3.
Asset lookup 4. Manifests 5. ActionView helpers 6. Development vs. production