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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
140
CSC307 Lecture 07
javiergs
PRO
1
560
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
750
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
610
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
150
15年続くIoTサービスのSREエンジニアが挑む分散トレーシング導入
melonps
2
230
Raku Raku Notion 20260128
hareyakayuruyaka
0
360
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
1k
AI & Enginnering
codelynx
0
120
並行開発のためのコードレビュー
miyukiw
0
1.1k
SourceGeneratorのススメ
htkym
0
200
CSC307 Lecture 05
javiergs
PRO
0
500
Featured
See All Featured
Visualization
eitanlees
150
17k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Everyday Curiosity
cassininazir
0
130
Designing Powerful Visuals for Engaging Learning
tmiket
0
240
The Invisible Side of Design
smashingmag
302
51k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.3k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
54
Code Reviewing Like a Champion
maltzj
527
40k
Optimizing for Happiness
mojombo
379
71k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
170
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.1k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
750
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