Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Turing School - Understanding the Asset Pipeline
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Turing School
April 11, 2017
Programming
0
43
Turing School - Understanding the Asset Pipeline
Rails Asset Pipeline Lesson Slides
Turing School
April 11, 2017
Tweet
Share
Other Decks in Programming
See All in Programming
MUSUBIXとは
nahisaho
0
140
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
180
開発者から情シスまで - 多様なユーザー層に届けるAPI提供戦略 / Postman API Night Okinawa 2026 Winter
tasshi
0
210
AWS re:Invent 2025参加 直前 Seattle-Tacoma Airport(SEA)におけるハードウェア紛失インシデントLT
tetutetu214
2
120
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
6.1k
CSC307 Lecture 06
javiergs
PRO
0
690
Fluid Templating in TYPO3 14
s2b
0
130
Data-Centric Kaggle
isax1015
2
780
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
140
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
1k
CSC307 Lecture 08
javiergs
PRO
0
670
Grafana:建立系統全知視角的捷徑
blueswen
0
330
Featured
See All Featured
The Curious Case for Waylosing
cassininazir
0
240
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
98
Building AI with AI
inesmontani
PRO
1
700
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
Ethics towards AI in product and experience design
skipperchong
2
200
Accessibility Awareness
sabderemane
0
56
4 Signs Your Business is Dying
shpigford
187
22k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
1.8k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
The Cult of Friendly URLs
andyhume
79
6.8k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
470
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
320
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