SlideShare a Scribd company logo
5 Quick JavaScript
Performance
Improvement Tips
30 January 2014
Twitter handle:
@therockncoder
The Rock n Coder
• http://therockncoder.blogspot.com	

• http://www.youtube.com/user/rockncoder	

• https://github.com/Rockncoder	

• http://www.slideshare.net/rockncoder
Our Agenda
• Why Performance Matters	

• 5 Performance Tips	

• Resources	

• Summary
Why Performance
Matters?
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
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
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
5 Performance Tips
Tip #5
Use as few files as
possible
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
Tip #4
Prefer local variables
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
Var Scoping Demo
Prefer local variables
• Property chains similar to var scoping	

• Objects closer in the chain found quicker
Property Chain Demo
Tip #3
Reduce the work done
in loops
Reduce the work done
in loops

• No real speed difference between: for, while
and do_while	


• Avoid for_in	

• (Watch library based for_each)
Tip #2
Watch your plugins
Watch your plugins
• Know what your plugins do	

• Be sure to evaluate different plugins	

• Example jQuery.js or Zepto.js
jQuery Demo
Tip #1
Avoid the DOM
Avoid the DOM
• The DOM is REALLY Slow	

• Avoid accessing it when possible	

• Do work offline then update DOM
DOM Access Demo
Resources
Resources
• Microsoft Ajax Minifier


http://ajaxmin.codeplex.com/	


• Google Closure Tools


https://developers.google.com/closure/	


• Yahoo YSlow


http://developer.yahoo.com/yslow/
Books
• High Performance JavaScript

Nicholas C. Zakas	


• JavaScript Ninja


John Resig & Bear Bibeaults	


• JavaScript: The Good Parts

Douglas Crockford

Summary
Summary
• Avoid the DOM 	

• Watch your plugins 	

• Reduce the work done in loops 	

• Prefer local variables	

• Use as few files as possible
The Rock n Coder
• http://therockncoder.blogspot.com	

• http://www.youtube.com/user/rockncoder	

• https://github.com/Rockncoder	

• http://www.slideshare.net/rockncoder

More Related Content

What's hot (20)

PDF
Get Hip with JHipster - Denver JUG 2015
Matt Raible
 
PDF
What Multisite can do for You - Anthony Cole - WordCamp Sydney 2012
WordCamp Sydney
 
PDF
Testing Angular 2 Applications - HTML5 Denver 2016
Matt Raible
 
PDF
Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - S...
Ezra Gildesgame
 
PDF
jQuery Conference San Diego 2014 - Web Performance
dmethvin
 
PDF
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx 2015
Matt Raible
 
PDF
Testing Mobile JavaScript
jeresig
 
PDF
Getting Started with Angular - Stormpath Webinar, January 2017
Matt Raible
 
PDF
WAG the Blog
Evan Volgas
 
PDF
Kickstarter Your Node.JS Application
Hengki Sihombing
 
PDF
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - GeekOut 2016
Matt Raible
 
PDF
On Selecting JavaScript Frameworks (Women Who Code 10/15)
Zoe Landon
 
PDF
Responsive, adaptive and responsible - keynote at NebraskaJS
Christian Heilmann
 
PDF
Build the mobile web you want
k88hudson
 
PPTX
Optimizing Your Site for Holiday Traffic
WP Engine UK
 
KEY
New Perspectives on Performance
mennovanslooten
 
PDF
Task runners + theming automating your workflow
Joshua Gilmer
 
PDF
Hello npm
Muyuu Fujita
 
PDF
Get Hip with JHipster - Colorado Springs OSS Meetup April 2016
Matt Raible
 
PPTX
HyperDB, MySQL Performance, & Flavors of MySQL
Evan Volgas
 
Get Hip with JHipster - Denver JUG 2015
Matt Raible
 
What Multisite can do for You - Anthony Cole - WordCamp Sydney 2012
WordCamp Sydney
 
Testing Angular 2 Applications - HTML5 Denver 2016
Matt Raible
 
Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - S...
Ezra Gildesgame
 
jQuery Conference San Diego 2014 - Web Performance
dmethvin
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx 2015
Matt Raible
 
Testing Mobile JavaScript
jeresig
 
Getting Started with Angular - Stormpath Webinar, January 2017
Matt Raible
 
WAG the Blog
Evan Volgas
 
Kickstarter Your Node.JS Application
Hengki Sihombing
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - GeekOut 2016
Matt Raible
 
On Selecting JavaScript Frameworks (Women Who Code 10/15)
Zoe Landon
 
Responsive, adaptive and responsible - keynote at NebraskaJS
Christian Heilmann
 
Build the mobile web you want
k88hudson
 
Optimizing Your Site for Holiday Traffic
WP Engine UK
 
New Perspectives on Performance
mennovanslooten
 
Task runners + theming automating your workflow
Joshua Gilmer
 
Hello npm
Muyuu Fujita
 
Get Hip with JHipster - Colorado Springs OSS Meetup April 2016
Matt Raible
 
HyperDB, MySQL Performance, & Flavors of MySQL
Evan Volgas
 

Similar to 5 Quick JavaScript Performance Improvement Tips (20)

PPTX
30 JavaScript optimization tips
Hovhannes Avoyan
 
PPTX
Java script performance tips
Shakti Shrestha
 
PPT
High Performance Ajax Applications
Julien Lecomte
 
PPT
High Performance Ajax Applications 1197671494632682 2
Niti Chotkaew
 
KEY
A rough guide to JavaScript Performance
allmarkedup
 
PDF
Performance Optimization and JavaScript Best Practices
Doris Chen
 
PPTX
JavaScript front end performance optimizations
Chris Love
 
PPT
Ajax Performance
kaven yan
 
PDF
Developing High Performance Web Apps
Timothy Fisher
 
PPT
Performance optimization - JavaScript
Filip Mares
 
PPTX
7 tips for javascript rich ajax websites
oazabir
 
PPT
Web performance essentials - Goodies
Jerry Emmanuel
 
PDF
How DRY impacts JavaScript performance // Faster JavaScript execution for the...
Mathias Bynens
 
PDF
10 Groovy Little JavaScript Tips
Troy Miles
 
PDF
Ajax Performance Tuning and Best Practices
Doris Chen
 
PPT
Smarr Oscon 2007
briandemant
 
PPT
Os Smarr
oscon2007
 
PDF
Client Side Performance In Web Applications
vladungureanu
 
PDF
Front-end optimisation & jQuery Internals (Pycon)
Artur Cistov
 
PPTX
Creating high-performance-web-sites
chaos_bit
 
30 JavaScript optimization tips
Hovhannes Avoyan
 
Java script performance tips
Shakti Shrestha
 
High Performance Ajax Applications
Julien Lecomte
 
High Performance Ajax Applications 1197671494632682 2
Niti Chotkaew
 
A rough guide to JavaScript Performance
allmarkedup
 
Performance Optimization and JavaScript Best Practices
Doris Chen
 
JavaScript front end performance optimizations
Chris Love
 
Ajax Performance
kaven yan
 
Developing High Performance Web Apps
Timothy Fisher
 
Performance optimization - JavaScript
Filip Mares
 
7 tips for javascript rich ajax websites
oazabir
 
Web performance essentials - Goodies
Jerry Emmanuel
 
How DRY impacts JavaScript performance // Faster JavaScript execution for the...
Mathias Bynens
 
10 Groovy Little JavaScript Tips
Troy Miles
 
Ajax Performance Tuning and Best Practices
Doris Chen
 
Smarr Oscon 2007
briandemant
 
Os Smarr
oscon2007
 
Client Side Performance In Web Applications
vladungureanu
 
Front-end optimisation & jQuery Internals (Pycon)
Artur Cistov
 
Creating high-performance-web-sites
chaos_bit
 
Ad

More from Troy Miles (20)

PDF
Fast C++ Web Servers
Troy Miles
 
PDF
Node Boot Camp
Troy Miles
 
PDF
AWS Lambda Function with Kotlin
Troy Miles
 
PDF
React Native One Day
Troy Miles
 
PDF
React Native Evening
Troy Miles
 
PDF
Intro to React
Troy Miles
 
PDF
React Development with the MERN Stack
Troy Miles
 
PDF
Angular Application Testing
Troy Miles
 
PDF
ReactJS.NET
Troy Miles
 
PDF
What is Angular version 4?
Troy Miles
 
PDF
Angular Weekend
Troy Miles
 
PDF
From MEAN to the MERN Stack
Troy Miles
 
PDF
Functional Programming in JavaScript
Troy Miles
 
PDF
Functional Programming in Clojure
Troy Miles
 
PDF
MEAN Stack Warm-up
Troy Miles
 
PDF
The JavaScript You Wished You Knew
Troy Miles
 
PDF
Game Design and Development Workshop Day 1
Troy Miles
 
PDF
Build a Game in 60 minutes
Troy Miles
 
PDF
Quick & Dirty & MEAN
Troy Miles
 
PDF
A Quick Intro to ReactiveX
Troy Miles
 
Fast C++ Web Servers
Troy Miles
 
Node Boot Camp
Troy Miles
 
AWS Lambda Function with Kotlin
Troy Miles
 
React Native One Day
Troy Miles
 
React Native Evening
Troy Miles
 
Intro to React
Troy Miles
 
React Development with the MERN Stack
Troy Miles
 
Angular Application Testing
Troy Miles
 
ReactJS.NET
Troy Miles
 
What is Angular version 4?
Troy Miles
 
Angular Weekend
Troy Miles
 
From MEAN to the MERN Stack
Troy Miles
 
Functional Programming in JavaScript
Troy Miles
 
Functional Programming in Clojure
Troy Miles
 
MEAN Stack Warm-up
Troy Miles
 
The JavaScript You Wished You Knew
Troy Miles
 
Game Design and Development Workshop Day 1
Troy Miles
 
Build a Game in 60 minutes
Troy Miles
 
Quick & Dirty & MEAN
Troy Miles
 
A Quick Intro to ReactiveX
Troy Miles
 
Ad

Recently uploaded (20)

PDF
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PPTX
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 

5 Quick JavaScript Performance Improvement Tips

  • 3. The Rock n Coder • http://therockncoder.blogspot.com • http://www.youtube.com/user/rockncoder • https://github.com/Rockncoder • http://www.slideshare.net/rockncoder
  • 4. Our Agenda • Why Performance Matters • 5 Performance Tips • Resources • Summary
  • 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
  • 10. Tip #5 Use as few files as possible
  • 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
  • 12. Tip #4 Prefer local variables
  • 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
  • 15. Prefer local variables • Property chains similar to var scoping • Objects closer in the chain found quicker
  • 17. Tip #3 Reduce the work done in loops
  • 18. Reduce the work done in loops • No real speed difference between: for, while and do_while • Avoid for_in • (Watch library based for_each)
  • 19. Tip #2 Watch your plugins
  • 20. Watch your plugins • Know what your plugins do • Be sure to evaluate different plugins • Example jQuery.js or Zepto.js
  • 23. Avoid the DOM • The DOM is REALLY Slow • Avoid accessing it when possible • Do work offline then update DOM
  • 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