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
Optimising your JavaScript
Search
Wendy Liu
February 26, 2014
Programming
550
1
Share
Optimising your JavaScript
Presented at ConFoo (
http://confoo.ca/en/2014/session/optimising-your-javascript
)
Wendy Liu
February 26, 2014
More Decks by Wendy Liu
See All by Wendy Liu
Git and Github: Version control for a happier you
dellsystem
0
360
Git and Github: Tips and tricks
dellsystem
2
400
Git and Github: version control for the 21st century
dellsystem
1
320
Django: The web framework for perfectionists with deadlines
dellsystem
0
440
Git and GitHub: an introduction
dellsystem
2
280
What's in a name? Using first names as features for gender inference in Twitter
dellsystem
1
500
diva.js: A web-based document viewer for high-resolution images
dellsystem
0
370
Other Decks in Programming
See All in Programming
LLM Plugin for Node-REDの利用方法と開発について
404background
0
140
次世代リンターで探る、tsgo 時代における型認識カスタムルールの現実解
ytakahashii
3
1.3k
GitHub Copilot CLIのいいところ
htkym
2
1.2k
デフォルト運用のCodeRabbit、1年で何が変わったか / How CodeRabbit Changed Our Code Review in 1 Year
bake0937
1
110
Transactional Change Stream Processing With Debezium and Apache Flink
gunnarmorling
1
140
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
480
密結合なバックエンドから TypeScript のコードを生成する
kemuridama
1
390
AIエージェントと協働するCLI開発 — BunとOpenClawで学んだこと
yoshikouki
1
220
権限チェックの一貫性を型で守る TypeScript による多層防御
mnch
4
970
OCRを使ってゲームのアイテムをデータ化する
kishikawakatsumi
0
120
iOS26時代の新規アプリ開発
yuukiw00w
0
210
バックエンドにElysiaJSを採用して気付いた、良い点・悪い点
wanko_it
1
190
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
37
7.3k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.2k
Visualization
eitanlees
152
17k
RailsConf 2023
tenderlove
30
1.5k
4 Signs Your Business is Dying
shpigford
187
22k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
230
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
WCS-LA-2024
lcolladotor
0
610
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
140
Navigating Team Friction
lara
192
16k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.5k
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