SlideShare a Scribd company logo
A ROUGH GUIDE to



JavaScript
Performance
                   by Mark Perkins, July 2010
A *rough* guide....
A *rough* guide....


General principles for you to take and build
on
A *rough* guide....


General principles for you to take and build
on

3 tips for loadtime performance
A *rough* guide....


General principles for you to take and build
on

3 tips for loadtime performance

3 principles for speedy runtimes
A *rough* guide....


General principles for you to take and build
on

3 tips for loadtime performance

3 principles for speedy runtimes

Seconds, not milliseconds (possibly...)
We’re NOT going to cover (much...)
We’re NOT going to cover (much...)


General frontend performance topics
We’re NOT going to cover (much...)


General frontend performance topics

Crazy language optimisations eg.
~~( 1*‘12.34’ )
We’re NOT going to cover (much...)


General frontend performance topics

Crazy language optimisations eg.
~~( 1*‘12.34’ )

Advanced testing tools
A rough guide to JavaScript Performance
A rough guide to JavaScript Performance
A rough guide to JavaScript Performance
LOADTIME
Steve Souders
“Only 10-20% of
                       the end user
                       response time is
                       spent downloading
                       the HTML
                       document.

                       The other
                       80-90% is spent



           ’ Golden Rule
Steve Souders
Some facts of life
Some facts of life


HTTP requests are expensive
Some facts of life


HTTP requests are expensive

Browsers are single threaded (ignoring
web workers)
Some facts of life


HTTP requests are expensive

Browsers are single threaded (ignoring
web workers)

2-4 resources downloaded in parallel per
host
Some facts of life


HTTP requests are expensive

Browsers are single threaded (ignoring
web workers)

2-4 resources downloaded in parallel per
host

<script> tags disable parallel downloads
and block all rendering below them
JS 1

       JS 2


                     IMAGE 1


                     IMAGE 2

              time
<script>




1. Move <script> tags to the bottom (of the
page)
A rough guide to JavaScript Performance
A rough guide to JavaScript Performance
A rough guide to JavaScript Performance
FOUJC!!
A rough guide to JavaScript Performance
A rough guide to JavaScript Performance
2. Concatenate, Minimise, GZip
Concatenation
Concatenation


Less HTTP requests === :-)
Concatenation


Less HTTP requests === :-)

But... rarely used scripts may be better off
loaded where appropriate.
Concatenation


Less HTTP requests === :-)

But... rarely used scripts may be better off
loaded where appropriate.

Automate: Sprockets, php-sprockets etc
Minification
Minification


Strips whitespace and comments out,
shortens variables in functions
Minification


Strips whitespace and comments out,
shortens variables in functions

Minify, don’t Pack!
Minification


Strips whitespace and comments out,
shortens variables in functions

Minify, don’t Pack!

Anything that obfuscates code and requires
eval’ing has a performance hit. Avoid!
GZip your JS!
GZip your JS!


GZip is the way forward. Use it.
GZip your JS!


GZip is the way forward. Use it.

Can reduce file size by up to 70%
GZip your JS!


GZip is the way forward. Use it.

Can reduce file size by up to 70%

No whitespace removal or variable alteration
- easy to debug
GZip your JS!


GZip is the way forward. Use it.

Can reduce file size by up to 70%

No whitespace removal or variable alteration
- easy to debug

Configure once and forget about it, all taken
care of by the server
GZip your JS!


GZip is the way forward. Use it.

Can reduce file size by up to 70%

No whitespace removal or variable alteration
- easy to debug

Configure once and forget about it, all taken
care of by the server
3. Load scripts in a non-blocking
               way
A rough guide to JavaScript Performance
Dynamic scripts
Dynamic scripts


Add <script> tags via DOM methods to
avoid blocking of other page processes
Dynamic scripts


Add <script> tags via DOM methods to
avoid blocking of other page processes

Only FF and Opera guarantee execution
order (concatenation can help with this)
Dynamic scripts


Add <script> tags via DOM methods to
avoid blocking of other page processes

Only FF and Opera guarantee execution
order (concatenation can help with this)

Use onload callbacks to tell us when it’s
loaded, can nest to ensure execution order
is respected
A rough guide to JavaScript Performance
A rough guide to JavaScript Performance
A little help from your friends...
A little help from your friends...


Lazy Loader: http://github.com/rgrove/
lazyload/
A little help from your friends...


Lazy Loader: http://github.com/rgrove/
lazyload/

LabJS: http://labjs.com
A little help from your friends...


Lazy Loader: http://github.com/rgrove/
lazyload/

LabJS: http://labjs.com
Loadtime recap!
Loadtime recap!


1. Move <script> tags to the bottom of the
page
Loadtime recap!


1. Move <script> tags to the bottom of the
page

2. Concatenate, Minimise, GZip
Loadtime recap!


1. Move <script> tags to the bottom of the
page

2. Concatenate, Minimise, GZip

3. Load scripts in a non-blocking way
RUNTIME
1. Be afraid of the DOM!
About that DOM...
About that DOM...


The DOM is a language independent API for
working with XML/HTML documents.
About that DOM...


The DOM is a language independent API for
working with XML/HTML documents.

The JS engine and the DOM are implemented
separately in browsers.
About that DOM...


The DOM is a language independent API for
working with XML/HTML documents.

The JS engine and the DOM are implemented
separately in browsers.

Every time you touch the DOM you incur a
performance penalty.
Big DOM: Scary!



                  Little DOM:
                  Not so scary.
Keep bridge crossings to a minimum!




                       DOM-LAND




JAVASCRIPT-
   VILLE
A rough guide to JavaScript Performance
‘Cache’ your DOM
selection results for re-use
A rough guide to JavaScript Performance
Minimise this kind of DOM
insertion wherever possible
A rough guide to JavaScript Performance
Event Delegation FTW!
2. Write lazy code
Lazy code does as little work as
possible, without repetition
Lazy code does as little work as
possible, without repetition
Lazy code does as little work as
possible, without repetition
Lazy code does as little work as
possible, without repetition
Lazy code does as little work as
possible, without repetition
3. Keep your Ajax under control
Caching is King!!
Caching is King!!


Use GET requests
Caching is King!!


Use GET requests

Tailor URLs to the user where possible:
Caching is King!!


Use GET requests

Tailor URLs to the user where possible:
http://mydomain/ajax/info.php?
user_id=129473
Caching is King!!


Use GET requests

Tailor URLs to the user where possible:
http://mydomain/ajax/info.php?
user_id=129473

Ensure appropriate headers are sent by the
server
Caching is King!!


Use GET requests

Tailor URLs to the user where possible:
http://mydomain/ajax/info.php?
user_id=129473

Ensure appropriate headers are sent by the
server
(ie. a far future Expires header)
Caching is King!!


Use GET requests

Tailor URLs to the user where possible:
http://mydomain/ajax/info.php?
user_id=129473

Ensure appropriate headers are sent by the
server
(ie. a far future Expires header)
Be smart about return data
Be smart about return data


HTML > JSONP > JSON > XML
Be smart about return data


HTML > JSONP > JSON > XML

Return HTML wherever possible - templating
in JS is slow, your server is fast, use it!
Be smart about return data


HTML > JSONP > JSON > XML

Return HTML wherever possible - templating
in JS is slow, your server is fast, use it!

JSONP - no parse time, already in a native
format
Be smart about return data


HTML > JSONP > JSON > XML

Return HTML wherever possible - templating
in JS is slow, your server is fast, use it!

JSONP - no parse time, already in a native
format

JSON - needs parsing/evaluating first
Be smart about return data


HTML > JSONP > JSON > XML

Return HTML wherever possible - templating
in JS is slow, your server is fast, use it!

JSONP - no parse time, already in a native
format

JSON - needs parsing/evaluating first
Runtime recap!
Runtime recap!


1. Be afraid of the DOM
Runtime recap!


1. Be afraid of the DOM

2. Write lazy code
Runtime recap!


1. Be afraid of the DOM

2. Write lazy code

3. Keep your Ajax under control
Additional Resources

Books:

High Performance Websites: http://amzn.to/bbBTln
Even Faster Websites: http://amzn.to/a7iJmo
High Performance JavaScript: http://amzn.to/9CgsfA
JavaScript Rocks! http://javascriptrocks.com/performance/

Interwebs:

Steve Souders HPWS blog: http://stevesouders.com/
Yahoo Exceptional Performance resources: http://developer.yahoo.com/
performance/
YUI blog (performance category): http://yuiblog.com/blog/category/
performance
Understanding site load waterfalls: http://bit.ly/9KkmN1
Nokia JS Performance best practices: http://bit.ly/aYLXLU
Velocity Conference: http://en.oreilly.com/velocity2010
My ‘performance’ tag on Delicious: http://delicious.com/allmarkedup/
performance

Recommended

Real-time Ruby for the Real-time Web
Real-time Ruby for the Real-time Web
Ilya Grigorik
 
Ruby in the Browser - RubyConf 2011
Ruby in the Browser - RubyConf 2011
Ilya Grigorik
 
Ruby as a glue language
Ruby as a glue language
quakewang
 
Coldfusion
Coldfusion
Ram
 
Web Development with Python and Django
Web Development with Python and Django
Michael Pirnat
 
Mojolicious and REST
Mojolicious and REST
Jonas Brømsø
 
Battle of NoSQL stars: Amazon's SDB vs MongoDB vs CouchDB vs RavenDB
Battle of NoSQL stars: Amazon's SDB vs MongoDB vs CouchDB vs RavenDB
Jesse Wolgamott
 
OSS Security the hard way
OSS Security the hard way
Hiroshi SHIBATA
 
The Future of library dependency management of Ruby
The Future of library dependency management of Ruby
Hiroshi SHIBATA
 
44CON London 2015 - Going AUTH the Rails on a Crazy Train
44CON London 2015 - Going AUTH the Rails on a Crazy Train
44CON
 
HipHop VM: overclocking Symfony
HipHop VM: overclocking Symfony
Vadim Borodavko
 
Perl6 meets JVM
Perl6 meets JVM
Tokuhiro Matsuno
 
ApacheCon 2014 - What's New in Apache httpd 2.4
ApacheCon 2014 - What's New in Apache httpd 2.4
Jim Jagielski
 
WASM! WASI! WAGI! WAT?
WASM! WASI! WAGI! WAT?
Stefan Baumgartner
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHP
Jonathan Klein
 
Scaling PHP to 40 Million Uniques
Scaling PHP to 40 Million Uniques
Jonathan Klein
 
Serverless Rust
Serverless Rust
Stefan Baumgartner
 
Devignition 2011
Devignition 2011
tobiascrawley
 
Jruby a Pi and a database
Jruby a Pi and a database
Philipp Fehre
 
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
Kyle Drake
 
Test::Kantan - Perl and Testing
Test::Kantan - Perl and Testing
Tokuhiro Matsuno
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and servers
Tatsuhiko Miyagawa
 
Distributed Queue System using Gearman
Distributed Queue System using Gearman
Eric Cho
 
What's new in RubyGems3
What's new in RubyGems3
Hiroshi SHIBATA
 
Productive web applications that run only on the frontend
Productive web applications that run only on the frontend
Stefan Adolf
 
Building reusable components with generics and protocols
Building reusable components with generics and protocols
Donny Wals
 
SydPHP March 2012 Meetup
SydPHP March 2012 Meetup
Graham Weldon
 
How to create a blog
How to create a blog
Huda Shubair
 
10 j som una nació nosaltres decidim gràcies!
10 j som una nació nosaltres decidim gràcies!
CDC Dreta Eixample
 
bagsplanet
bagsplanet
bagsplanet
 

More Related Content

What's hot (19)

The Future of library dependency management of Ruby
The Future of library dependency management of Ruby
Hiroshi SHIBATA
 
44CON London 2015 - Going AUTH the Rails on a Crazy Train
44CON London 2015 - Going AUTH the Rails on a Crazy Train
44CON
 
HipHop VM: overclocking Symfony
HipHop VM: overclocking Symfony
Vadim Borodavko
 
Perl6 meets JVM
Perl6 meets JVM
Tokuhiro Matsuno
 
ApacheCon 2014 - What's New in Apache httpd 2.4
ApacheCon 2014 - What's New in Apache httpd 2.4
Jim Jagielski
 
WASM! WASI! WAGI! WAT?
WASM! WASI! WAGI! WAT?
Stefan Baumgartner
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHP
Jonathan Klein
 
Scaling PHP to 40 Million Uniques
Scaling PHP to 40 Million Uniques
Jonathan Klein
 
Serverless Rust
Serverless Rust
Stefan Baumgartner
 
Devignition 2011
Devignition 2011
tobiascrawley
 
Jruby a Pi and a database
Jruby a Pi and a database
Philipp Fehre
 
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
Kyle Drake
 
Test::Kantan - Perl and Testing
Test::Kantan - Perl and Testing
Tokuhiro Matsuno
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and servers
Tatsuhiko Miyagawa
 
Distributed Queue System using Gearman
Distributed Queue System using Gearman
Eric Cho
 
What's new in RubyGems3
What's new in RubyGems3
Hiroshi SHIBATA
 
Productive web applications that run only on the frontend
Productive web applications that run only on the frontend
Stefan Adolf
 
Building reusable components with generics and protocols
Building reusable components with generics and protocols
Donny Wals
 
SydPHP March 2012 Meetup
SydPHP March 2012 Meetup
Graham Weldon
 
The Future of library dependency management of Ruby
The Future of library dependency management of Ruby
Hiroshi SHIBATA
 
44CON London 2015 - Going AUTH the Rails on a Crazy Train
44CON London 2015 - Going AUTH the Rails on a Crazy Train
44CON
 
HipHop VM: overclocking Symfony
HipHop VM: overclocking Symfony
Vadim Borodavko
 
ApacheCon 2014 - What's New in Apache httpd 2.4
ApacheCon 2014 - What's New in Apache httpd 2.4
Jim Jagielski
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHP
Jonathan Klein
 
Scaling PHP to 40 Million Uniques
Scaling PHP to 40 Million Uniques
Jonathan Klein
 
Jruby a Pi and a database
Jruby a Pi and a database
Philipp Fehre
 
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
Kyle Drake
 
Test::Kantan - Perl and Testing
Test::Kantan - Perl and Testing
Tokuhiro Matsuno
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and servers
Tatsuhiko Miyagawa
 
Distributed Queue System using Gearman
Distributed Queue System using Gearman
Eric Cho
 
Productive web applications that run only on the frontend
Productive web applications that run only on the frontend
Stefan Adolf
 
Building reusable components with generics and protocols
Building reusable components with generics and protocols
Donny Wals
 
SydPHP March 2012 Meetup
SydPHP March 2012 Meetup
Graham Weldon
 

Viewers also liked (17)

How to create a blog
How to create a blog
Huda Shubair
 
10 j som una nació nosaltres decidim gràcies!
10 j som una nació nosaltres decidim gràcies!
CDC Dreta Eixample
 
bagsplanet
bagsplanet
bagsplanet
 
New media rev
New media rev
Huda Shubair
 
Whmis safety training 2
Whmis safety training 2
jjayne
 
Myori流ストレス回避術
Myori流ストレス回避術
moyori
 
New media rev
New media rev
Huda Shubair
 
New media Revolution
New media Revolution
Huda Shubair
 
Whmis safety training 3
Whmis safety training 3
jjayne
 
Jornadas2
Jornadas2
Avanzosc, S.L.
 
11 building an electric circuit
11 building an electric circuit
mrtangextrahelp
 
prueba
prueba
k_rlitos
 
Ch10 final
Ch10 final
Sarath Nair
 
Check it Out! (Respect)
Check it Out! (Respect)
Judy Cannedy
 
Chris mc cann_presentation
Chris mc cann_presentation
Influence People
 
Orris aster court premier
Orris aster court premier
Green Realtech Projects Pvt. Ltd
 
Botanicals Bamboo Leaf 01a
Botanicals Bamboo Leaf 01a
Eileen TOGASHI
 
How to create a blog
How to create a blog
Huda Shubair
 
10 j som una nació nosaltres decidim gràcies!
10 j som una nació nosaltres decidim gràcies!
CDC Dreta Eixample
 
Whmis safety training 2
Whmis safety training 2
jjayne
 
Myori流ストレス回避術
Myori流ストレス回避術
moyori
 
New media Revolution
New media Revolution
Huda Shubair
 
Whmis safety training 3
Whmis safety training 3
jjayne
 
11 building an electric circuit
11 building an electric circuit
mrtangextrahelp
 
Check it Out! (Respect)
Check it Out! (Respect)
Judy Cannedy
 
Chris mc cann_presentation
Chris mc cann_presentation
Influence People
 
Botanicals Bamboo Leaf 01a
Botanicals Bamboo Leaf 01a
Eileen TOGASHI
 

Similar to A rough guide to JavaScript Performance (20)

Developing High Performance Web Apps
Developing High Performance Web Apps
Timothy Fisher
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011
Timothy Fisher
 
Building high performance web apps.
Building high performance web apps.
Arshak Movsisyan
 
Widget Summit 2008
Widget Summit 2008
Volkan Unsal
 
Front-end optimisation & jQuery Internals
Front-end optimisation & jQuery Internals
Artur Cistov
 
PrairieDevCon 2014 - Web Doesn't Mean Slow
PrairieDevCon 2014 - Web Doesn't Mean Slow
dmethvin
 
Smarr Oscon 2007
Smarr Oscon 2007
briandemant
 
Os Smarr
Os Smarr
oscon2007
 
High Performance Ajax Applications 1197671494632682 2
High Performance Ajax Applications 1197671494632682 2
Niti Chotkaew
 
High Performance Ajax Applications
High Performance Ajax Applications
Julien Lecomte
 
Front-end optimisation & jQuery Internals (Pycon)
Front-end optimisation & jQuery Internals (Pycon)
Artur Cistov
 
10 Tips to make your Website lightning-fast - SMX Stockholm 2012
10 Tips to make your Website lightning-fast - SMX Stockholm 2012
Bastian Grimm
 
10 things you can do to speed up your web app today stir trek edition
10 things you can do to speed up your web app today stir trek edition
Chris Love
 
Building performance into the new yahoo homepage presentation
Building performance into the new yahoo homepage presentation
masudakram
 
Performance on the Yahoo! Homepage
Performance on the Yahoo! Homepage
Nicholas Zakas
 
Performance Tuning Web Apps - The Need For Speed
Performance Tuning Web Apps - The Need For Speed
Vijay Rayapati
 
10 Things You Can Do to Speed Up Your Web App Today
10 Things You Can Do to Speed Up Your Web App Today
Chris Love
 
Web Performance Optimization (WPO)
Web Performance Optimization (WPO)
Betclic Everest Group Tech Team
 
Frontend performance
Frontend performance
sacred 8
 
Html Optimization for SEO
Html Optimization for SEO
S. Ernest Paul ✪
 
Developing High Performance Web Apps
Developing High Performance Web Apps
Timothy Fisher
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011
Timothy Fisher
 
Building high performance web apps.
Building high performance web apps.
Arshak Movsisyan
 
Widget Summit 2008
Widget Summit 2008
Volkan Unsal
 
Front-end optimisation & jQuery Internals
Front-end optimisation & jQuery Internals
Artur Cistov
 
PrairieDevCon 2014 - Web Doesn't Mean Slow
PrairieDevCon 2014 - Web Doesn't Mean Slow
dmethvin
 
Smarr Oscon 2007
Smarr Oscon 2007
briandemant
 
High Performance Ajax Applications 1197671494632682 2
High Performance Ajax Applications 1197671494632682 2
Niti Chotkaew
 
High Performance Ajax Applications
High Performance Ajax Applications
Julien Lecomte
 
Front-end optimisation & jQuery Internals (Pycon)
Front-end optimisation & jQuery Internals (Pycon)
Artur Cistov
 
10 Tips to make your Website lightning-fast - SMX Stockholm 2012
10 Tips to make your Website lightning-fast - SMX Stockholm 2012
Bastian Grimm
 
10 things you can do to speed up your web app today stir trek edition
10 things you can do to speed up your web app today stir trek edition
Chris Love
 
Building performance into the new yahoo homepage presentation
Building performance into the new yahoo homepage presentation
masudakram
 
Performance on the Yahoo! Homepage
Performance on the Yahoo! Homepage
Nicholas Zakas
 
Performance Tuning Web Apps - The Need For Speed
Performance Tuning Web Apps - The Need For Speed
Vijay Rayapati
 
10 Things You Can Do to Speed Up Your Web App Today
10 Things You Can Do to Speed Up Your Web App Today
Chris Love
 
Frontend performance
Frontend performance
sacred 8
 

Recently uploaded (20)

WebdriverIO & JavaScript: The Perfect Duo for Web Automation
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
Edge AI and Vision Alliance
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
Edge AI and Vision Alliance
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 

A rough guide to JavaScript Performance

  • 1. A ROUGH GUIDE to JavaScript Performance by Mark Perkins, July 2010
  • 3. A *rough* guide.... General principles for you to take and build on
  • 4. A *rough* guide.... General principles for you to take and build on 3 tips for loadtime performance
  • 5. A *rough* guide.... General principles for you to take and build on 3 tips for loadtime performance 3 principles for speedy runtimes
  • 6. A *rough* guide.... General principles for you to take and build on 3 tips for loadtime performance 3 principles for speedy runtimes Seconds, not milliseconds (possibly...)
  • 7. We’re NOT going to cover (much...)
  • 8. We’re NOT going to cover (much...) General frontend performance topics
  • 9. We’re NOT going to cover (much...) General frontend performance topics Crazy language optimisations eg. ~~( 1*‘12.34’ )
  • 10. We’re NOT going to cover (much...) General frontend performance topics Crazy language optimisations eg. ~~( 1*‘12.34’ ) Advanced testing tools
  • 16. “Only 10-20% of the end user response time is spent downloading the HTML document. The other 80-90% is spent ’ Golden Rule Steve Souders
  • 18. Some facts of life HTTP requests are expensive
  • 19. Some facts of life HTTP requests are expensive Browsers are single threaded (ignoring web workers)
  • 20. Some facts of life HTTP requests are expensive Browsers are single threaded (ignoring web workers) 2-4 resources downloaded in parallel per host
  • 21. Some facts of life HTTP requests are expensive Browsers are single threaded (ignoring web workers) 2-4 resources downloaded in parallel per host <script> tags disable parallel downloads and block all rendering below them
  • 22. JS 1 JS 2 IMAGE 1 IMAGE 2 time
  • 23. <script> 1. Move <script> tags to the bottom (of the page)
  • 33. Concatenation Less HTTP requests === :-) But... rarely used scripts may be better off loaded where appropriate.
  • 34. Concatenation Less HTTP requests === :-) But... rarely used scripts may be better off loaded where appropriate. Automate: Sprockets, php-sprockets etc
  • 36. Minification Strips whitespace and comments out, shortens variables in functions
  • 37. Minification Strips whitespace and comments out, shortens variables in functions Minify, don’t Pack!
  • 38. Minification Strips whitespace and comments out, shortens variables in functions Minify, don’t Pack! Anything that obfuscates code and requires eval’ing has a performance hit. Avoid!
  • 40. GZip your JS! GZip is the way forward. Use it.
  • 41. GZip your JS! GZip is the way forward. Use it. Can reduce file size by up to 70%
  • 42. GZip your JS! GZip is the way forward. Use it. Can reduce file size by up to 70% No whitespace removal or variable alteration - easy to debug
  • 43. GZip your JS! GZip is the way forward. Use it. Can reduce file size by up to 70% No whitespace removal or variable alteration - easy to debug Configure once and forget about it, all taken care of by the server
  • 44. GZip your JS! GZip is the way forward. Use it. Can reduce file size by up to 70% No whitespace removal or variable alteration - easy to debug Configure once and forget about it, all taken care of by the server
  • 45. 3. Load scripts in a non-blocking way
  • 48. Dynamic scripts Add <script> tags via DOM methods to avoid blocking of other page processes
  • 49. Dynamic scripts Add <script> tags via DOM methods to avoid blocking of other page processes Only FF and Opera guarantee execution order (concatenation can help with this)
  • 50. Dynamic scripts Add <script> tags via DOM methods to avoid blocking of other page processes Only FF and Opera guarantee execution order (concatenation can help with this) Use onload callbacks to tell us when it’s loaded, can nest to ensure execution order is respected
  • 53. A little help from your friends...
  • 54. A little help from your friends... Lazy Loader: http://github.com/rgrove/ lazyload/
  • 55. A little help from your friends... Lazy Loader: http://github.com/rgrove/ lazyload/ LabJS: http://labjs.com
  • 56. A little help from your friends... Lazy Loader: http://github.com/rgrove/ lazyload/ LabJS: http://labjs.com
  • 58. Loadtime recap! 1. Move <script> tags to the bottom of the page
  • 59. Loadtime recap! 1. Move <script> tags to the bottom of the page 2. Concatenate, Minimise, GZip
  • 60. Loadtime recap! 1. Move <script> tags to the bottom of the page 2. Concatenate, Minimise, GZip 3. Load scripts in a non-blocking way
  • 62. 1. Be afraid of the DOM!
  • 64. About that DOM... The DOM is a language independent API for working with XML/HTML documents.
  • 65. About that DOM... The DOM is a language independent API for working with XML/HTML documents. The JS engine and the DOM are implemented separately in browsers.
  • 66. About that DOM... The DOM is a language independent API for working with XML/HTML documents. The JS engine and the DOM are implemented separately in browsers. Every time you touch the DOM you incur a performance penalty.
  • 67. Big DOM: Scary! Little DOM: Not so scary.
  • 68. Keep bridge crossings to a minimum! DOM-LAND JAVASCRIPT- VILLE
  • 70. ‘Cache’ your DOM selection results for re-use
  • 72. Minimise this kind of DOM insertion wherever possible
  • 76. Lazy code does as little work as possible, without repetition
  • 77. Lazy code does as little work as possible, without repetition
  • 78. Lazy code does as little work as possible, without repetition
  • 79. Lazy code does as little work as possible, without repetition
  • 80. Lazy code does as little work as possible, without repetition
  • 81. 3. Keep your Ajax under control
  • 83. Caching is King!! Use GET requests
  • 84. Caching is King!! Use GET requests Tailor URLs to the user where possible:
  • 85. Caching is King!! Use GET requests Tailor URLs to the user where possible: http://mydomain/ajax/info.php? user_id=129473
  • 86. Caching is King!! Use GET requests Tailor URLs to the user where possible: http://mydomain/ajax/info.php? user_id=129473 Ensure appropriate headers are sent by the server
  • 87. Caching is King!! Use GET requests Tailor URLs to the user where possible: http://mydomain/ajax/info.php? user_id=129473 Ensure appropriate headers are sent by the server (ie. a far future Expires header)
  • 88. Caching is King!! Use GET requests Tailor URLs to the user where possible: http://mydomain/ajax/info.php? user_id=129473 Ensure appropriate headers are sent by the server (ie. a far future Expires header)
  • 89. Be smart about return data
  • 90. Be smart about return data HTML > JSONP > JSON > XML
  • 91. Be smart about return data HTML > JSONP > JSON > XML Return HTML wherever possible - templating in JS is slow, your server is fast, use it!
  • 92. Be smart about return data HTML > JSONP > JSON > XML Return HTML wherever possible - templating in JS is slow, your server is fast, use it! JSONP - no parse time, already in a native format
  • 93. Be smart about return data HTML > JSONP > JSON > XML Return HTML wherever possible - templating in JS is slow, your server is fast, use it! JSONP - no parse time, already in a native format JSON - needs parsing/evaluating first
  • 94. Be smart about return data HTML > JSONP > JSON > XML Return HTML wherever possible - templating in JS is slow, your server is fast, use it! JSONP - no parse time, already in a native format JSON - needs parsing/evaluating first
  • 96. Runtime recap! 1. Be afraid of the DOM
  • 97. Runtime recap! 1. Be afraid of the DOM 2. Write lazy code
  • 98. Runtime recap! 1. Be afraid of the DOM 2. Write lazy code 3. Keep your Ajax under control
  • 99. Additional Resources Books: High Performance Websites: http://amzn.to/bbBTln Even Faster Websites: http://amzn.to/a7iJmo High Performance JavaScript: http://amzn.to/9CgsfA JavaScript Rocks! http://javascriptrocks.com/performance/ Interwebs: Steve Souders HPWS blog: http://stevesouders.com/ Yahoo Exceptional Performance resources: http://developer.yahoo.com/ performance/ YUI blog (performance category): http://yuiblog.com/blog/category/ performance Understanding site load waterfalls: http://bit.ly/9KkmN1 Nokia JS Performance best practices: http://bit.ly/aYLXLU Velocity Conference: http://en.oreilly.com/velocity2010 My ‘performance’ tag on Delicious: http://delicious.com/allmarkedup/ performance