Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Optimising your JavaScript
Search
Wendy Liu
February 26, 2014
Programming
560
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
380
Git and Github: Tips and tricks
dellsystem
2
410
Git and Github: version control for the 21st century
dellsystem
1
330
Django: The web framework for perfectionists with deadlines
dellsystem
0
450
Git and GitHub: an introduction
dellsystem
2
290
What's in a name? Using first names as features for gender inference in Twitter
dellsystem
1
530
diva.js: A web-based document viewer for high-resolution images
dellsystem
0
380
Other Decks in Programming
See All in Programming
ジョジョの世界をXRで再現する
mofurune
0
180
GraphQL の onError と Nullability のこれから
quramy
0
130
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
120
[2026-10-14](C)Re:ゼロから始める異世界生活〜始まりの終わりと終わりの始まり〜
tosite
0
140
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
190
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
440
APNsからLive Activityを開始する話
yumnumm
0
170
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
340
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
No More NoSuchMethodError
exoego
1
110
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
360
Performance Optimization With LLMs
xleitix
0
170
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
What the history of the web can teach us about the future of AI
inesmontani
PRO
2
750
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
610
Faster Mobile Websites
deanohume
310
32k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
530
The SEO Collaboration Effect
kristinabergwall1
1
600
Building AI with AI
inesmontani
PRO
1
1.3k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
GitHub's CSS Performance
jonrohan
1033
470k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
550
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
Discover your Explorer Soul
emna__ayadi
2
1.3k
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