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
290
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Front-end optimization
Tools and techniques for delivering content faster
RJ Zaworski
June 19, 2014
More Decks by RJ Zaworski
See All by RJ Zaworski
Computing Lessons from the Atomic Age: Complexity, Safety, and Ethics
rjz
0
110
Beyond the Single-Page App: React and the Servers that Serve it
rjz
0
99
Typesafe(ish) React
rjz
1
700
Front-end optimization
rjz
1
480
Technical Interviewing
rjz
0
270
Interop! Building a better Backbone.View
rjz
0
110
HTTP Security
rjz
2
200
Other Decks in Programming
See All in Programming
Claspは野良GASの夢をみるか
takter00
0
180
The Arts and Crafts of Work in the AI Era — Toward Mastery in Software Development
kuranuki
1
750
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4k
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
210
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
110
3Dシーンの圧縮
fadis
1
740
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
2
570
「エンジニアインターン、どうやって取った?」準備のリアルを語るLT会 Progate BAR
akiomatic
0
130
LLM Plugin for Node-REDの利用方法と開発について
404background
0
170
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
3
1.3k
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
120
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
270
Featured
See All Featured
Designing for Timeless Needs
cassininazir
1
250
Statistics for Hackers
jakevdp
799
230k
We Have a Design System, Now What?
morganepeng
55
8.2k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
180
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4k
Raft: Consensus for Rubyists
vanstee
141
7.5k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
190
Navigating Weather and Climate Data
rabernat
0
220
GraphQLとの向き合い方2022年版
quramy
50
15k
Claude Code のすすめ
schroneko
67
230k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
330
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