JavaScript is arguably the most important language in the world. It comes included in nearly every desktop and mobile browser. It powers the client-side of apps like Facebook and GMail. It is the language of choice for mobile development environments like Apccelerator's Titanium and Apache's Cordova (aka Adobe's PhoneGap). It is even on the server now in Node.js. Yet when programmer's run into performance issue with JavaScript their first inclination is to blame its interpreted nature, not realizing that simple changes in the structure of their code can result in sometimes significant improvements in performance. In this session I will show five quick changes you can make to your JavaScript code to improve its performance and explain why they work.
3. The Rock n Coder
• http://therockncoder.blogspot.com
• http://www.youtube.com/user/rockncoder
• https://github.com/Rockncoder
• http://www.slideshare.net/rockncoder
6. Why Performance
Matters?
• 47% of consumers expect a 2 second page
load
• 40% abandon a page that takes 3 seconds
or more to load
• A 1 second delay in page response can
result in a 7% reduction in conversions
7. If an e-commerce site is making
$100,000 a day in sales, a 1 second
page delay could potentially cost you
$2.5 million in lost sales every year
8. We should forget about small efficiencies, say
about 97% of the time: premature optimization
is the root of all evil.Yet we should not pass up
our opportunities in that critical 3%.
D. Knuth
11. Use as few files as
possible
• Browser can load multiple files at a time
• But only one JS file at a time
• Concatenate multiple JS file into one
• Compress JS files
• Prefer JS at the bottom of the HTML file
13. Prefer local variables
• Variables in scope found quicker
• JS search local scope, then global
• with creates a new scope level ahead of
local
• closures also create new scope level
26. Resources
• Microsoft Ajax Minifier
http://ajaxmin.codeplex.com/
• Google Closure Tools
https://developers.google.com/closure/
• Yahoo YSlow
http://developer.yahoo.com/yslow/
27. Books
• High Performance JavaScript
Nicholas C. Zakas
• JavaScript Ninja
John Resig & Bear Bibeaults
• JavaScript: The Good Parts
Douglas Crockford
29. Summary
• Avoid the DOM
• Watch your plugins
• Reduce the work done in loops
• Prefer local variables
• Use as few files as possible
30. The Rock n Coder
• http://therockncoder.blogspot.com
• http://www.youtube.com/user/rockncoder
• https://github.com/Rockncoder
• http://www.slideshare.net/rockncoder