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
Front-end optimization
Search
RJ Zaworski
June 19, 2014
Programming
4
240
Front-end optimization
Tools and techniques for delivering content faster
RJ Zaworski
June 19, 2014
Tweet
Share
More Decks by RJ Zaworski
See All by RJ Zaworski
Computing Lessons from the Atomic Age: Complexity, Safety, and Ethics
rjz
0
52
Beyond the Single-Page App: React and the Servers that Serve it
rjz
0
62
Typesafe(ish) React
rjz
1
630
Front-end optimization
rjz
1
380
Technical Interviewing
rjz
0
190
Interop! Building a better Backbone.View
rjz
0
56
HTTP Security
rjz
2
140
Other Decks in Programming
See All in Programming
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
6
670
php-conference-japan-2024
tasuku43
0
410
Lookerは可視化だけじゃない。UIコンポーネントもあるんだ!
ymd65536
1
100
Findy Team+ Awardを受賞したかった!ベストプラクティス応募内容をふりかえり、開発生産性向上もふりかえる / Findy Team Plus Award BestPractice and DPE Retrospective 2024
honyanya
0
130
fs2-io を試してたらバグを見つけて直した話
chencmd
0
280
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
220
DevFest - Serverless 101 with Google Cloud Functions
tunmise
0
130
AWSのLambdaで PHPを動かす選択肢
rinchoku
2
360
情報漏洩させないための設計
kubotak
5
1.2k
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
720
KubeCon NA 2024の全DB関連セッションを紹介
nnaka2992
0
110
各クラウドサービスにおける.NETの対応と見解
ymd65536
0
230
Featured
See All Featured
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.7k
Done Done
chrislema
182
16k
Building an army of robots
kneath
302
44k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
How to train your dragon (web standard)
notwaldorf
88
5.8k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Designing for humans not robots
tammielis
250
25k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Mobile First: as difficult as doing things right
swwweet
222
9k
Transcript
Front-end optimization Make it fast! rj zaworski, versal inc. ·
@rjzaworski · github.com/rjz
Any questions?
The First Rule of Optimization Don’t.
The Second Rule of Optimization Optimize for dev time.
So why do we care? ★ 47% of consumers expect
a web page to load in 2 seconds or less. ★ 40% of people abandon a website that takes more than 3 seconds to load. (http://blog.kissmetrics.com/loading-time/)
It's even worse for mobile. “73% of mobile internet users
say that they’ve encountered a website that was too slow to load.” (http://blog.kissmetrics.com/loading-time/)
How do we know our site is slow?
Measurement Tools ★ Chrome DevTools ★ Google PageSpeed ★ YSlow
(
The internet is pretty much a garden hose.
Why is it slow? ★ Bandwidth: how big is the
pipe?
Why is it slow? ★ Bandwidth: how big is the
pipe? ★ Volume: how much needs to be delivered?
Why is it slow? ★ Bandwidth: how big is the
pipe? ★ Volume: how much needs to be delivered? ★ Proximity: how far away are the ends?
So how do we make it faster?
Is the pipe clogged? ★ Concurrent connections are limited per
host ★ Browser mileage may vary (http://www.browserscope.org/?category=network)
Script elements ...can either reference external scripts...
Script elements ...or inline scripts..
Script elements ...but either use will exhibit blocking!
Well, that’s not good.
Script elements ★ Place scripts at bottom of page
Script elements ★ Place scripts at bottom of page ★
Set and for external scripts
Async ain’t everything ★ Browsers will prefetch when possible ★
Execution is still deferred
When will async scripts run? ¯\_(ツ)_/¯
Wait for predictable events
Wait for predictable events
But we’re still making a lot of requests.
HTTP isn’t free ★ Every request has headers
HTTP isn’t free ★ Every request has headers ★ Keep
an eye on that !
HTTP isn’t free ★ Every request has headers ★ Keep
an eye on that ! ★ Batch overhead where possible
Concatenate external files ★ Reduce HTTP overhead ★ Reduce concurrent
requests
Concatenate external files ★ Reduce HTTP overhead ★ Reduce concurrent
requests
And small is beautiful.
Minify concatenated files ★ uglifyjs is pretty good ★ closure
compiler is really good ★ Hint: build tools support these
Serve compressed content ★ Browsers support gzip
Serve compressed content ★ Browsers support gzip ★ Servers do,
too!
Stylesheets? Same tricks. ★ won’t block ★ each triggers a
request ★ cssmin is pretty good
Preprocessing ★ Use a preprocessor (SASS, Stylus, LESS) ★ Concatenation,
minification are free Optimize for dev time!
Inline small scripts ★ Bundle HTTP overhead with page request
★ The price: caching
Did someone say caching?
Caching: the Big Idea ★ Less distance == faster ★
Keep content as close as possible
Caching: the bad news There are only two hard things
in Computer Science: cache invalidation and naming things. —Phil Karlton
Enable browser caching ★ HTTP can help
Enable browser caching ★ HTTP can help ★ Use header
(http://www.mobify.com/blog/beginners-guide-to-http-cache-headers/)
Enable browser caching ★ HTTP can help ★ Use header
★ Set if content will change
What about content that always changes?
Enable browser caching ★ HTTP can help ★ Use header
★ Set if content will change ★ Use with dynamic content
We can tell the browser even more.
Browser caching Describe app dependencies in a manifest
Browser caching Describe app dependencies in a manifest (https://developer.mozilla.org/en-US/docs/Web/HTML/Using_the_application_cache)
Browser caching ★ static assets
Browser caching ★ static assets ★ declare paths that require
access
Browser caching ★ static assets ★ declare paths that require
access ★ provide a
Use a Content Delivery Network ★ located near the users
★ replicate automagically ★ == fast
Use a Content Delivery Network Share common assets with everyone
else ★ cdnjs.com ★ jsDelivr.com ★ Google Hosted Libraries
Use a Content Delivery Network ★ Failure happens
Use a Content Delivery Network ★ Failure happens ★ So
keep a local fallback handy
Server-side caching On the application server ★ Minimize disk I/O
★ Cache popular files in memory Optimize for dev time!
Summing up ★ Bandwidth: how big is the pipe? ★
Volume: how much needs to be delivered? ★ Proximity: how far away are the ends?
Summing up ★ Bandwidth: avoid blocking behaviors ★ Volume: minimize
request count and size ★ Proximity: use browser caching and a CDN
Summing up ★ Bandwidth: avoid blocking behaviors ★ Volume: minimize
request count and size ★ Proximity: use browser caching and a CDN ★ Optimize for dev time!
Thank you! rj zaworski, versal inc. · @rjzaworski · github.com/rjz