Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Optimising your JavaScript
Search
Wendy Liu
February 26, 2014
Programming
1
530
Optimising your JavaScript
Presented at ConFoo (
http://confoo.ca/en/2014/session/optimising-your-javascript
)
Wendy Liu
February 26, 2014
Tweet
Share
More Decks by Wendy Liu
See All by Wendy Liu
Git and Github: Version control for a happier you
dellsystem
0
330
Git and Github: Tips and tricks
dellsystem
2
400
Git and Github: version control for the 21st century
dellsystem
1
310
Django: The web framework for perfectionists with deadlines
dellsystem
0
430
Git and GitHub: an introduction
dellsystem
2
270
What's in a name? Using first names as features for gender inference in Twitter
dellsystem
1
470
diva.js: A web-based document viewer for high-resolution images
dellsystem
0
360
Other Decks in Programming
See All in Programming
WebRTC、 綺麗に見るか滑らかに見るか
sublimer
1
140
CSC305 Lecture 15
javiergs
PRO
0
240
無秩序からの脱却 / Emergence from chaos
nrslib
2
12k
堅牢なフロントエンドテスト基盤を構築するために行った取り組み
shogo4131
6
1.9k
ViewファーストなRailsアプリ開発のたのしさ
sugiwe
0
390
dotfiles 式年遷宮 令和最新版
masawada
1
670
AWS CDKの推しポイントN選
akihisaikeda
1
240
Herb to ReActionView: A New Foundation for the View Layer @ San Francisco Ruby Conference 2025
marcoroth
0
240
レイトレZ世代に捧ぐ、今からレイトレを始めるための小径
ichi_raven
0
490
新卒エンジニアのプルリクエスト with AI駆動
fukunaga2025
0
140
AIコードレビューがチームの"文脈"を 読めるようになるまで
marutaku
0
310
非同期処理の迷宮を抜ける: 初学者がつまづく構造的な原因
pd1xx
1
570
Featured
See All Featured
How to Ace a Technical Interview
jacobian
280
24k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
The Language of Interfaces
destraynor
162
25k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
196
69k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Facilitating Awesome Meetings
lara
57
6.7k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
Unsuck your backbone
ammeep
671
58k
Optimizing for Happiness
mojombo
379
70k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
690
Making the Leap to Tech Lead
cromwellryan
135
9.6k
[RailsConf 2023] Rails as a piece of cake
palkan
58
6.1k
Transcript
optimising your javascript Wendy Liu February 26, 2014 :: ConFoo
BEFOre we begin ... Is optimisation even necessary?
IF SO ... What should you optimise?
PROFILING Chrome: bit.ly/chromeprofiler
tradeoffs Performance vs. readability
None
optimisation tips
faster code delivery Minimisation CDNs GZIP compression
event-handling Use a library Delegation
event-handling Use a library Delegation <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li>
... </ul>
unnecessary work Don't do it Check before calling Throttle event-handling
speeding up code Native functions Combine timers Avoid anything eval-like
speeding up code Native functions Combine timers Avoid anything eval-like
for (...) { element = $(...); ... }
speeding up code Native functions Combine timers Avoid anything eval-like
for (...) { element = document.getElementById(...); ... }
speeding up code Native functions Combine timers Avoid anything eval-like
setTimeout('someFunction', 1000); setTimeout(someFunction, 1000)
don't use: with try-catch in a loop globals for in
speeding up code Cache out of scope variables Cache array.length
String-building Cache calculations someFunction = someObject.someFunction; for (...) { someFunction(...); }
speeding up code Cache out of scope variables Cache array.length
String-building Cache calculations for (var i = 0, l = arr.length; i < l; i++) { ... }
speeding up code Cache out of scope variables Cache array.length
String-building Cache calculations var stringBuilder = []; for (...) { stringBuilder.push('a'); } var string = stringBuilder.join('');
speeding up code Cache out of scope variables Cache array.length
String-building Cache calculations
working with the dom Use CSS Keep it small (virtual
rendering) Minimise reflows/repaints position: absolute; left: 50%; margin-left: -200px; width: 400px;
Minimising reflows innerHTML/$.html over creating nodes Batch setting styles Stay
low in the DOM tree Detach/hide nodes
Minimising reflows Cache node properties Position: fixed/absolute for animations Avoid
tables for layout
HEAVY frameworks Do you really need them?
caching AJAX requests Server-side scripts Client-side caching (localStorage)
using prototypes properly Functions Value-type instance variables var Person =
function() {}; Person.prototype.doSomething = function(...) { ... }; var Person = function() { this.doSomething = function(...) { ... }; };
avoid closures Source of memory leaks Reuse static functions Adds
level to scope chain
faking it Loading screens Thumbnail previews for images Pre-loading
more resources Google/Stackoverflow jsperf.com bit.ly/canvas-perf bit.ly/high-performance-js (book) bit.ly/google-optimising-js bit.ly/repaint-reflow bit.ly/chrome-profiler
bit.ly/js-var-access
thanks! @dellsystem