SlideShare a Scribd company logo
jQuery internals and front­end 
          optimisation




       Artur Cistov – PyCon Ireland 2010
Why bother?


500ms slower = 20% drop in traffic (Google)
400ms slower = 5­9% drop in full­page traffic (Yahoo)
100ms slower = 1% drop in sales (Amazon)




                         Source: http://www.slideshare.net/stoyan/yslow-20-presentation
Why bother?


Google added site speed as a factor to search 
ranking on April 9, 2010
Why bother?

 
    Less CPU power and memory than    
 on the desktop
 
    Slower connections
 
    25Kb cache limit per file on iPhone




       Source: http://yuiblog.com/blog/2008/02/06/iphone-cacheability/
280slides.com
Quake II GWT Port




          Source: http://www.youtube.com/watch?v=XhMN0wlITLk
Front-end optimisation & jQuery Internals (Pycon)
Front-end optimisation & jQuery Internals (Pycon)
Plan for this talk


  Front­end optimisation

  jQuery under the hood

  jQuery optimisation

  Tools & Resources
Front-end optimisation & jQuery Internals (Pycon)
Front-end optimisation & jQuery Internals (Pycon)
Front­end Optimisation

1. Dependency loading
2. Initial Rendering
3. Post­load responsiveness
1. Dependency Loading

  Total time needed to download all the 
  page assets (images, stylesheets, scripts 
  etc.)

  Ideally, full download only happens once, 
  later on assets are taken from cache
Full vs. Empty Cache
Dependency Loading Optimisation 
          Techniques

  Minimising HTTP Requests

  Minimising total filesize

  Maximising parallel downloads

  Addressing blocking behaviour
developer.yahoo.com/performance/
Minimising HTTP Requests


  Combining multiple JS & CSS files, 
  combining images into sprites

  Avoiding requests alltogether with 
  caching (Expires & ETag headers)
Image Sprite Examples
Filesize


  Gzipping

  Minifying scripts & styles

  Compressing images
Maximising parallel downloads


  Browsers have 2­6 simultaneous request 
  limit per domain name. 

  Subdomains are treated as different 
  domains in this context
Maximising parallel downloads


  LABjs ­ “all­purpose, on­demand 
  JavaScript loader, capable of loading 
  any JavaScript resource, from any 
  location, into any page, at any time.”

  Allows to load scripts in parallel

  http://labjs.com/
Statically loading scripts 
        (blocking)




         Source: http://blog.getify.com/2009/11/labjs-new-hotness-for-script-loading/
Dynamically loading scripts




          Source: http://blog.getify.com/2009/11/labjs-new-hotness-for-script-loading/
Front-end optimisation & jQuery Internals (Pycon)
Front-end optimisation & jQuery Internals (Pycon)
Non­blocking loading: 
  Google Analytics
2. Speeding Up Initial Page 
        Rendering
Speeding up onload render ­ 
            techniques

  Assets order

  .js class trick

  Lazy Loading

  Banners & tracking scripts

  Flash of Unscripted Content
Assets Order


  CSS at the top, JavaScript at the bottom

  Avoid @import for CSS
Lazy Loading

  Deferring loading of a component after 
  page load

  Module loader coming in jQuery 1.5?

  Facebook Primer library
.js class trick
Performance of 3rd Party Content




                     Source: http://www.stevesouders.com/p3pc/
3rd Party Content


    9 additional HTTP requests for Digg 
    Widget, 107 kB total download size, 665 
    ms median load time
Flash of unscripted content problem



    Elements are rendered, but their 
    behaviour hasn't been assigned yet
Front-end optimisation & jQuery Internals (Pycon)
Traditional Solution:
Script immediately after element
One of the modern solutions:
     Google Analytics Approach
3. Post­load responsiveness
Many factors




       Source: http://ejohn.org/blog/javascript-performance-stack/
Post­load responsiveness 
            techniques


  Minimising Reflows & Repaints

  JavaScript Optimisation
Repaints

  Occur when something made visible or 
  hidden without altering the layout. 

  E.g. outline added to an element, 
  background color or visibility changed

  Repainting is expensive.
Reflows


  Reflow occurs when the DOM is 
  manipulated in a way it affects the 
  layout. E.g. style is changed to affect the 
  layout, className property is changed or 
  browser window is resized. 

  Reflows are even more expensive than 
  repainting.
Reflows
Reflows are very expensive in terms of 
performance, and is one of the main causes 
of slow DOM scripts, especially on devices 
with low processing power, such as phones. 
In many cases, they are equivalent to laying 
out the entire page again.



                   Source http://dev.opera.com/articles/view/efficient-javascript/?page=3#reflow
Reflows are triggered by


    Style is changed that affects the layout

    className property of an element is changed

    DOM modifications (e.g. adding new 
    elements)

    using offsetWidth / offsetHeight / 
    getComputedStyle
Minimising reflows

    Batch style updates




                          Source http://www.phpied.com/rendering-repaint-reflowrelayout-restyle/
Minimising reflows

Batch DOM changes and/or perform them off the DOM:

    Detaching element from the DOM, making changes 
    & reinserting 

    Hide element before changes, apply them & show 
    again

    innerHTML

    DOMDocumentFragment
Minimising reflows




Source http://wiki.forum.nokia.com/index.php/JavaScript_Performance_Best_Practices#Use_createDocumentFragment.28.29
Minimising reflows

    Apply animations with position fixed or 
    absolute
Underlying Problem of Single 
              Thread

  UI rendering & JavaScript share the 
  same thread of execution

  Long­running scripts can freeze UI or 
  cause 'Do you want to stop this script' 
  prompts
Web Workers API

   Draft Recommendation — 12 May 2010

   Background workers running scripts in   
  parallel to the main page

  Message passing
Some JavaScript Optimisations


  Variable lookup performance

  Avoiding eval

  Caching array length in loops

  Using try/catch sparingly
Front­end Optimisation Recap:

1. Dependency loading (HTTP requests, 
  filesize, parallel downloads, blocking)
2. Rendering (Asset order, Lazy loading, 
  Flash of unstyled content)
3. Post­load responsiveness (Reflows & 
  repaints, JavaScript optimisations)
Front-end optimisation & jQuery Internals (Pycon)
jQuery Usage




         Source:http://trends.builtwith.com/javascript/JQuery
jQuery Usage




         Source:http://trends.builtwith.com/javascript/JQuery
jQuery Performance




          Source: http://www.flickr.com/photos/jeresig/4366089661/
jQuery Productivity




         Source: http://www.slideshare.net/paul.irish/perfcompression
Barebones jQuery 0.1
http://github.com/cistov/Barebones­jQuery




                       http://www.flickr.com/photos/voss/71431079/
Sample Usage
Full Source:
1. Initialisation
2. jQuery.prototype
3. Utility methods
4. Aliases
5. Sample Plug­ins
jQuery Instance 
(Matched/Wrapped Set)
Two fundamental pieces of 
      functionality in jQuery


  jQuery instance methods 
e.g. $('#nav a').show();

  utility ('static') methods
$.noConflict();
jQuery optimisation
Front-end optimisation & jQuery Internals (Pycon)
Front-end optimisation & jQuery Internals (Pycon)
Front-end optimisation & jQuery Internals (Pycon)
Use the latest version
Sizzle selector engine
       
            Introduced in jQuery 1.3
           http://sizzlejs.com/
       
            Unlike earlier versions of 
           jQuery, it parses selectors 
           from right to left
       
            This is how browsers parse 
           CSS too
Specific on the right & generic on the left
Chain or cache selections
Don't act on empty sets
Class selectors
jQuery.fn.find
Events
Memory Leaks




  Source: http://msdn.microsoft.com/en-us/library/bb250448%28VS.85%29.aspx
Memory Leaks

    Avoid attaching objects to DOM nodes directly

    Use jQuery methods instead:
jQuery source viewer
 http://james.padolsey.com/jquery
jQuery: what's coming

  Ajax module rewrite

  Dependency & load management

  Templating

  Data binding

  Mobile support
jQuery Dublin
http://meetups.jquery.com/group/jquerydublin
Tools & Resources
Google Closure Compiler
Google Closure Compiler

   Open­source, written in Java & easy to extend

   Three modes 

   Up to 60­70% filesize savings

   Advanced code transforms based on syntax tree 
including constant & function inlining, dead code 
removal etc.

   Highlights code patterns that may not work well on 
all browsers

  jQuery gained 13% minification improvement by 
switiching to Google Compiler from YUI compressor
dynaTrace AJAX Edition
    http://ajax.dynatrace.com/
Cuzillion
Open­source web performance exploration tool 
Front-end optimisation & jQuery Internals (Pycon)
Books



        v
Links
Yahoo Exceptional performance team
ttp://developer.yahoo.com/performance/

Nokia JavaScript Performance Best Practices
http://wiki.forum.nokia.com/index.php/JavaScript_Performance_Best_Practices


Google Performance resources
http://code.google.com/speed/

Steve Souders, ex Chief Performance Yahoo
http://stevesouders.com/
Thanks

http://slideshare.net/cistov
 http://twitter.com/cistov
 http://github.com/cistov

More Related Content

What's hot (20)

PDF
Testing Mobile JavaScript
jeresig
 
PDF
Performance on the Yahoo! Homepage
Nicholas Zakas
 
PDF
YUI Test The Next Generation (YUIConf 2010)
Nicholas Zakas
 
PDF
Web Apps and more
Yan Shi
 
PDF
Dreamweaver CS6, jQuery, PhoneGap, mobile design
Dee Sadler
 
PDF
Making the web faster
Patrick Meenan
 
PPTX
Enough with the JavaScript already!
Nicholas Zakas
 
PDF
Vue js and Vue Material
Eueung Mulyana
 
PDF
HTML5 and the dawn of rich mobile web applications
James Pearce
 
PDF
Bootstrap and XPages (DanNotes 2013)
Mark Leusink
 
PDF
High Performance JavaScript - Fronteers 2010
Nicholas Zakas
 
PDF
Browser Performance Tests - Internet Explorer 11 vs Firefox 25 vs Google Chro...
MIDAS
 
PDF
High Performance Web Sites, With Ads: Don't let third parties make you slow
Tobias Järlund
 
PPTX
Bootstrap4XPages webinar
Mark Leusink
 
PPTX
Node JS Express : Steps to Create Restful Web App
Edureka!
 
PDF
01 overview-and-setup
snopteck
 
PDF
JS Module Server
Szabolcs Szabolcsi-Tóth
 
PDF
High Performance JavaScript - WebDirections USA 2010
Nicholas Zakas
 
ODP
How To Build a Multi-Field Search Page For Your XPages Application
Michael McGarel
 
PPTX
Chanhao Jiang And David Wei Presentation Quickling Pagecache
Ajax Experience 2009
 
Testing Mobile JavaScript
jeresig
 
Performance on the Yahoo! Homepage
Nicholas Zakas
 
YUI Test The Next Generation (YUIConf 2010)
Nicholas Zakas
 
Web Apps and more
Yan Shi
 
Dreamweaver CS6, jQuery, PhoneGap, mobile design
Dee Sadler
 
Making the web faster
Patrick Meenan
 
Enough with the JavaScript already!
Nicholas Zakas
 
Vue js and Vue Material
Eueung Mulyana
 
HTML5 and the dawn of rich mobile web applications
James Pearce
 
Bootstrap and XPages (DanNotes 2013)
Mark Leusink
 
High Performance JavaScript - Fronteers 2010
Nicholas Zakas
 
Browser Performance Tests - Internet Explorer 11 vs Firefox 25 vs Google Chro...
MIDAS
 
High Performance Web Sites, With Ads: Don't let third parties make you slow
Tobias Järlund
 
Bootstrap4XPages webinar
Mark Leusink
 
Node JS Express : Steps to Create Restful Web App
Edureka!
 
01 overview-and-setup
snopteck
 
JS Module Server
Szabolcs Szabolcsi-Tóth
 
High Performance JavaScript - WebDirections USA 2010
Nicholas Zakas
 
How To Build a Multi-Field Search Page For Your XPages Application
Michael McGarel
 
Chanhao Jiang And David Wei Presentation Quickling Pagecache
Ajax Experience 2009
 

Viewers also liked (8)

PPTX
High Performance Websites
Parham
 
ODP
A Holistic View of Website Performance
Rene Churchill
 
PDF
Drmx2004 Getting Started
UiTM
 
PPT
腾讯大讲堂09 如何建设高性能网站
topgeek
 
PDF
腾讯大讲堂09 如何建设高性能网站
fish_yy
 
PPS
Star of yesterday
Irene Aguiar
 
PDF
High Performance Front-End Development
drywallbmb
 
PPT
腾讯大讲堂09 如何建设高性能网站
George Ang
 
High Performance Websites
Parham
 
A Holistic View of Website Performance
Rene Churchill
 
Drmx2004 Getting Started
UiTM
 
腾讯大讲堂09 如何建设高性能网站
topgeek
 
腾讯大讲堂09 如何建设高性能网站
fish_yy
 
Star of yesterday
Irene Aguiar
 
High Performance Front-End Development
drywallbmb
 
腾讯大讲堂09 如何建设高性能网站
George Ang
 
Ad

Similar to Front-end optimisation & jQuery Internals (Pycon) (20)

PDF
Open-source website performance tools
Artur Cistov
 
PPTX
Drupal Frontend Performance and Scalability
Ashok Modi
 
PPT
Developing Java Web Applications
hchen1
 
PPTX
Starting with jQuery
Anil Kumar
 
PDF
DrupalCampLA 2011 - Drupal frontend-optimizing
Ashok Modi
 
PDF
Web app and more
faming su
 
PPT
High Performance Ajax Applications 1197671494632682 2
Niti Chotkaew
 
PPT
High Performance Ajax Applications
Julien Lecomte
 
PPT
High Performance Web Pages - 20 new best practices
Stoyan Stefanov
 
PDF
Web components api + Vuejs
Mikhail Kuznetcov
 
PPT
Testable client side_mvc_apps_in_javascript
Timothy Oxley
 
PDF
Template tuning for high performance
Chris Davenport
 
PPT
Csdn Drdobbs Tenni Theurer Yahoo
guestb1b95b
 
PPTX
Advanced JavaScript
Mahmoud Tolba
 
PPTX
Performace optimization (increase website speed)
clickramanm
 
PPT
TSSJS2010 Presenatation on: Performance Anti Patterns In Ajax Applications
guestc75cdc
 
PPT
Performance anti patterns in ajax applications
SergeyChernyshev
 
PDF
Using HttpWatch Plug-in with Selenium Automation in Java
Sandeep Tol
 
PPTX
JavaScript Presentation Frameworks and Libraries
Oleksii Prohonnyi
 
PPT
jQuery Tips Tricks Trivia
Cognizant
 
Open-source website performance tools
Artur Cistov
 
Drupal Frontend Performance and Scalability
Ashok Modi
 
Developing Java Web Applications
hchen1
 
Starting with jQuery
Anil Kumar
 
DrupalCampLA 2011 - Drupal frontend-optimizing
Ashok Modi
 
Web app and more
faming su
 
High Performance Ajax Applications 1197671494632682 2
Niti Chotkaew
 
High Performance Ajax Applications
Julien Lecomte
 
High Performance Web Pages - 20 new best practices
Stoyan Stefanov
 
Web components api + Vuejs
Mikhail Kuznetcov
 
Testable client side_mvc_apps_in_javascript
Timothy Oxley
 
Template tuning for high performance
Chris Davenport
 
Csdn Drdobbs Tenni Theurer Yahoo
guestb1b95b
 
Advanced JavaScript
Mahmoud Tolba
 
Performace optimization (increase website speed)
clickramanm
 
TSSJS2010 Presenatation on: Performance Anti Patterns In Ajax Applications
guestc75cdc
 
Performance anti patterns in ajax applications
SergeyChernyshev
 
Using HttpWatch Plug-in with Selenium Automation in Java
Sandeep Tol
 
JavaScript Presentation Frameworks and Libraries
Oleksii Prohonnyi
 
jQuery Tips Tricks Trivia
Cognizant
 
Ad

Recently uploaded (20)

PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
July Patch Tuesday
Ivanti
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 

Front-end optimisation & jQuery Internals (Pycon)