SlideShare a Scribd company logo
$ will do everything for us


                  Naga HaRISH
                  ShareOurIdeas.com
Agenda
$ Few words about jQuery
$ Why we need it
$ Optimization tips
  # Load jQuery
  # Using Selectors
  # And more

                               …more worth is waiting…!
$(jQuery)
$ this is a new kind of JavaScript Library.
$ It is a lightweight cross-browser (FF,GC,IE,OP,SF).
$ And it is the most popular JS library in use
  today.
$ It was released in 2006 1st Half and current
  version is 1.7.1

                                                 $.Next()
Each( features )
$ LESS CODE DO MORE
$ We can do Element Styling, Events Handling,
  DOM manipulation, Animations and Ajax.
$ We can develop site rapidly. Because it was
  ready with cool stuff.
$ It is most popular and many awesome plugins.
$ Having good Support and Documentation.
$(“.Tips”) - Load jQuery Script
$ Load minified file, because it small in size (31k
  < 229k)
$ It is best to use Content Delivery
  Network(CDN) URL
$ Let’s Google or Microsoft host jQuery file for U
  # Google src http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
  # Microsoft src http://ajax.microsoft.com/ajax/jquery/jquery-1.6.2.min.js
$ Forget About this if you work for local apps
Content Delivery Network
DEMO
jQuery.noConflict()
$ Use no conflict method when you using other
  Libraries.
$ Eg:-
   jQuery.noConflict()
   jQuery(“#Slide6”).next()
   (Or)
   var $j=jQuery.noConflict()
   $j(“#Slide6”).next()
DEMO
Start method
$ Best to use jQuery ready method.
$ Because we can use it more times, where javascript
  page onload is only once.
   $(document).ready(function() {
   //write your code here
   }

   (or)

   $(function(){
   //write your code here
   });
DEMO
Optimize performance, using selectors
$ Optimize selectors to descend from an ID, if
  possible. E.g:- $(“#id ul li”).hide()
$ Use tag names when selecting classes E.g:-
   $(“p.class”).show()

$ We can use comma(,) for multiple selectors
   E.g:- $(“p, ul li,div).css(‘color’,’#000’)


More here http://api.jquery.com/?s=selector
DEMO
Use Chaining
$ Take advantage of Chaining
$ Apply multiple effects and DOM manipulation
  @ a time
   Without Chaining                               With Chaining
   $(document).ready(function () {                $(document).ready(function () {
         $('#id').css('color', #143');                 $('#id').css('color',
         $('#id').html(' Request');               #200').html(' Response')
         $('#id').click(function () {                  .click(function () {
       //something                                    //something
   });                                                 });
   });                                            });
“.css(), .html(…) and more” functions return a jQuery object that can be worked
on instantly. So we use it right away to set the other properties like click event
handler.
DEMO
Use Caching
$ Caching is a great way to limit the number of
  times we need to traverse the DOM to find
  elements matched by the selectors.
  Without Caching                       With Caching
  $(document).ready(function () {       $(document).ready(function () {
        $('#id').css('color', #143');   var id=$('#id');
              :                         id.css('color', #143');
  If(isOk)                                           :
        $('#id').html(' Request');      If(isOk)
              :                               id.html(' Request');
  If(isEnable)                                       :
        $('#id').click(function () {    If(isEnable)
       //something                            id.click(function () {
  }); });                                    //something
                                        }); });
DEMO
Click vs Bind vs Live
$ Click is to handle click event on element
        $('#target').click(function() {
         alert('Handler for .click() called.');
        });
$ Bind is used to like same way, to add events.
  But not only click event. We can create our
  custom events too.
        $('#foo').bind('click', function() { $(this).toggleClass('entered'); });
        or
        $('#foo').bind('valid', function() { //Todo}); and we can fire this
        event like this $(‘#foo’).bind()
Click vs Bind vs Live
$ Live, will work same like Bind.
$ But, Bind can’t add event handler to run time
  add elements.
$ Live will automatically adds handlers for new
  elements.
Event delegation
$ Bind handler only once to the parent element
  containing all the children meant to have
  handlers.
                                           Using Event delegation
  Normal way                               $(document).ready(function () {
  $(document).ready(function () {          $('ul').delegate('click', 'li', function (e) {
  $('ul li').click(function () {               // if ($(e.target).is('li'))
                $(this).toggleClass('hig        $(e.target).toggleClass('highlight');
  hlight');                                     });
  }); });                                  });

$ Advantage of this is it will automatically bind
  click event for new(runtime add) element too.
DEMO
Minimize DOM manipulation
$ We have to minimize DOM operations (.append()
  .prepend() .after() .wrap() and ..)

Without temp variable (full         Without temp variable :-
DOM):-                              var myNumbers = $('#Numbers');
var myNumbers =                     var myString= '';
$('#Numbers');
                            for (i = 0; i < 1000; i++) {
for (i=0; i<1000; i++){       mystring += '<li>Number ' + i + '</li>';
   myNumbers.append('Number }
' + i);
}                           myList.html(myNumbers);
Minimize DOM manipulation(cont..)
$   Use template for array items
$   !dea from Microsoft
$   jQuery add in documentation
$   More http://api.jquery.com/jQuery.template/
$   http://api.jquery.com/jquery.tmpl/
DEMO
Use $(this) and this
$ $(this) is jQuery object
$ this is traditional HTML object

  $(document).ready(function () {
  $('ul li').click(function () {
              $(this).toggleClass('highlight');
  alert(this.innerHTML);
  });
  });
DEMO
Use data
$ Useful. It allows you to bind data to DOM
  elements without modifying the DOM.
$ For example:-
  # $("div").data("message", "Done!");
  # $("div").data("message");
  OR
  # <div data-error=“Error! :(“>…</div>
  # $("div").data("error");
DEMO
$(‘#Thanks’).show();



By Naga HaRISH
ShareOurIdeas.com
More you share, more you gain
Ad

More Related Content

What's hot (20)

jQuery
jQueryjQuery
jQuery
Mohammed Arif
 
Jquery-overview
Jquery-overviewJquery-overview
Jquery-overview
Isfand yar Khan
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
Anis Ahmad
 
D3.js and SVG
D3.js and SVGD3.js and SVG
D3.js and SVG
Karol Depka Pradzinski
 
jQuery
jQueryjQuery
jQuery
Vishwa Mohan
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
Marc Grabanski
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...
Thinqloud
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
manugoel2003
 
Jquery introduction
Jquery introductionJquery introduction
Jquery introduction
musrath mohammad
 
History of jQuery
History of jQueryHistory of jQuery
History of jQuery
jeresig
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
Remy Sharp
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
Simon Willison
 
jQuery - Tips And Tricks
jQuery - Tips And TricksjQuery - Tips And Tricks
jQuery - Tips And Tricks
Lester Lievens
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Zeeshan Khan
 
JavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScriptJavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScript
Laurence Svekis ✔
 
06 jQuery #burningkeyboards
06 jQuery  #burningkeyboards06 jQuery  #burningkeyboards
06 jQuery #burningkeyboards
Denis Ristic
 
jQuery
jQueryjQuery
jQuery
Mostafa Bayomi
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
Rod Johnson
 
jQuery Introduction
jQuery IntroductionjQuery Introduction
jQuery Introduction
Arwid Bancewicz
 
Jquery Best Practices
Jquery Best PracticesJquery Best Practices
Jquery Best Practices
brinsknaps
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
Anis Ahmad
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...
Thinqloud
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
manugoel2003
 
History of jQuery
History of jQueryHistory of jQuery
History of jQuery
jeresig
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
Remy Sharp
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
Simon Willison
 
jQuery - Tips And Tricks
jQuery - Tips And TricksjQuery - Tips And Tricks
jQuery - Tips And Tricks
Lester Lievens
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Zeeshan Khan
 
JavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScriptJavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScript
Laurence Svekis ✔
 
06 jQuery #burningkeyboards
06 jQuery  #burningkeyboards06 jQuery  #burningkeyboards
06 jQuery #burningkeyboards
Denis Ristic
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
Rod Johnson
 
Jquery Best Practices
Jquery Best PracticesJquery Best Practices
Jquery Best Practices
brinsknaps
 

Similar to Jquery optimization-tips (20)

jQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't KnowjQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't Know
girish82
 
jQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and PerformancejQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and Performance
Jonas De Smet
 
jQuery
jQueryjQuery
jQuery
Ivano Malavolta
 
J query training
J query trainingJ query training
J query training
FIS - Fidelity Information Services
 
22 j query1
22 j query122 j query1
22 j query1
Fajar Baskoro
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
Bastian Feder
 
Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9
Jack Franklin
 
Writing Maintainable JavaScript
Writing Maintainable JavaScriptWriting Maintainable JavaScript
Writing Maintainable JavaScript
Andrew Dupont
 
J query1
J query1J query1
J query1
Manav Prasad
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
smueller_sandsmedia
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
Bastian Feder
 
JavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talkJavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talk
Thomas Kjeldahl Nilsson
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQuery
Remy Sharp
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
toddbr
 
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScriptjQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
Guy Royse
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery Applications
Rebecca Murphey
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Nagaraju Sangam
 
Jquery Basics
Jquery BasicsJquery Basics
Jquery Basics
Umeshwaran V
 
Game jump: frontend introduction #1
Game jump: frontend introduction #1Game jump: frontend introduction #1
Game jump: frontend introduction #1
Sebastian Pożoga
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
Mevin Mohan
 
jQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't KnowjQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't Know
girish82
 
jQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and PerformancejQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and Performance
Jonas De Smet
 
Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9
Jack Franklin
 
Writing Maintainable JavaScript
Writing Maintainable JavaScriptWriting Maintainable JavaScript
Writing Maintainable JavaScript
Andrew Dupont
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
smueller_sandsmedia
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQuery
Remy Sharp
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
toddbr
 
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScriptjQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
Guy Royse
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery Applications
Rebecca Murphey
 
Game jump: frontend introduction #1
Game jump: frontend introduction #1Game jump: frontend introduction #1
Game jump: frontend introduction #1
Sebastian Pożoga
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
Mevin Mohan
 
Ad

Recently uploaded (20)

May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Building Connected Agents: An Overview of Google's ADK and A2A Protocol
Building Connected Agents:  An Overview of Google's ADK and A2A ProtocolBuilding Connected Agents:  An Overview of Google's ADK and A2A Protocol
Building Connected Agents: An Overview of Google's ADK and A2A Protocol
Suresh Peiris
 
Developing Product-Behavior Fit: UX Research in Product Development by Krysta...
Developing Product-Behavior Fit: UX Research in Product Development by Krysta...Developing Product-Behavior Fit: UX Research in Product Development by Krysta...
Developing Product-Behavior Fit: UX Research in Product Development by Krysta...
UXPA Boston
 
Best 10 Free AI Character Chat Platforms
Best 10 Free AI Character Chat PlatformsBest 10 Free AI Character Chat Platforms
Best 10 Free AI Character Chat Platforms
Soulmaite
 
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More MachinesRefactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Leon Anavi
 
AI and Gender: Decoding the Sociological Impact
AI and Gender: Decoding the Sociological ImpactAI and Gender: Decoding the Sociological Impact
AI and Gender: Decoding the Sociological Impact
SaikatBasu37
 
Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)
Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)
Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)
HusseinMalikMammadli
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
SOFTTECHHUB
 
React Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for SuccessReact Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for Success
Amelia Swank
 
Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...
Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...
Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...
UXPA Boston
 
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdf
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdfGoogle DeepMind’s New AI Coding Agent AlphaEvolve.pdf
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdf
derrickjswork
 
DNF 2.0 Implementations Challenges in Nepal
DNF 2.0 Implementations Challenges in NepalDNF 2.0 Implementations Challenges in Nepal
DNF 2.0 Implementations Challenges in Nepal
ICT Frame Magazine Pvt. Ltd.
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Maarten Verwaest
 
Right to liberty and security of a person.pdf
Right to liberty and security of a person.pdfRight to liberty and security of a person.pdf
Right to liberty and security of a person.pdf
danielbraico197
 
Computer Systems Quiz Presentation in Purple Bold Style (4).pdf
Computer Systems Quiz Presentation in Purple Bold Style (4).pdfComputer Systems Quiz Presentation in Purple Bold Style (4).pdf
Computer Systems Quiz Presentation in Purple Bold Style (4).pdf
fizarcse
 
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdfKit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Wonjun Hwang
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Building Connected Agents: An Overview of Google's ADK and A2A Protocol
Building Connected Agents:  An Overview of Google's ADK and A2A ProtocolBuilding Connected Agents:  An Overview of Google's ADK and A2A Protocol
Building Connected Agents: An Overview of Google's ADK and A2A Protocol
Suresh Peiris
 
Developing Product-Behavior Fit: UX Research in Product Development by Krysta...
Developing Product-Behavior Fit: UX Research in Product Development by Krysta...Developing Product-Behavior Fit: UX Research in Product Development by Krysta...
Developing Product-Behavior Fit: UX Research in Product Development by Krysta...
UXPA Boston
 
Best 10 Free AI Character Chat Platforms
Best 10 Free AI Character Chat PlatformsBest 10 Free AI Character Chat Platforms
Best 10 Free AI Character Chat Platforms
Soulmaite
 
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More MachinesRefactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Leon Anavi
 
AI and Gender: Decoding the Sociological Impact
AI and Gender: Decoding the Sociological ImpactAI and Gender: Decoding the Sociological Impact
AI and Gender: Decoding the Sociological Impact
SaikatBasu37
 
Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)
Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)
Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)
HusseinMalikMammadli
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
SOFTTECHHUB
 
React Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for SuccessReact Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for Success
Amelia Swank
 
Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...
Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...
Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...
UXPA Boston
 
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdf
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdfGoogle DeepMind’s New AI Coding Agent AlphaEvolve.pdf
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdf
derrickjswork
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Maarten Verwaest
 
Right to liberty and security of a person.pdf
Right to liberty and security of a person.pdfRight to liberty and security of a person.pdf
Right to liberty and security of a person.pdf
danielbraico197
 
Computer Systems Quiz Presentation in Purple Bold Style (4).pdf
Computer Systems Quiz Presentation in Purple Bold Style (4).pdfComputer Systems Quiz Presentation in Purple Bold Style (4).pdf
Computer Systems Quiz Presentation in Purple Bold Style (4).pdf
fizarcse
 
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdfKit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Wonjun Hwang
 
Ad

Jquery optimization-tips

  • 1. $ will do everything for us Naga HaRISH ShareOurIdeas.com
  • 2. Agenda $ Few words about jQuery $ Why we need it $ Optimization tips # Load jQuery # Using Selectors # And more …more worth is waiting…!
  • 3. $(jQuery) $ this is a new kind of JavaScript Library. $ It is a lightweight cross-browser (FF,GC,IE,OP,SF). $ And it is the most popular JS library in use today. $ It was released in 2006 1st Half and current version is 1.7.1 $.Next()
  • 4. Each( features ) $ LESS CODE DO MORE $ We can do Element Styling, Events Handling, DOM manipulation, Animations and Ajax. $ We can develop site rapidly. Because it was ready with cool stuff. $ It is most popular and many awesome plugins. $ Having good Support and Documentation.
  • 5. $(“.Tips”) - Load jQuery Script $ Load minified file, because it small in size (31k < 229k) $ It is best to use Content Delivery Network(CDN) URL $ Let’s Google or Microsoft host jQuery file for U # Google src http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js # Microsoft src http://ajax.microsoft.com/ajax/jquery/jquery-1.6.2.min.js $ Forget About this if you work for local apps
  • 8. jQuery.noConflict() $ Use no conflict method when you using other Libraries. $ Eg:- jQuery.noConflict() jQuery(“#Slide6”).next() (Or) var $j=jQuery.noConflict() $j(“#Slide6”).next()
  • 10. Start method $ Best to use jQuery ready method. $ Because we can use it more times, where javascript page onload is only once. $(document).ready(function() { //write your code here } (or) $(function(){ //write your code here });
  • 11. DEMO
  • 12. Optimize performance, using selectors $ Optimize selectors to descend from an ID, if possible. E.g:- $(“#id ul li”).hide() $ Use tag names when selecting classes E.g:- $(“p.class”).show() $ We can use comma(,) for multiple selectors E.g:- $(“p, ul li,div).css(‘color’,’#000’) More here http://api.jquery.com/?s=selector
  • 13. DEMO
  • 14. Use Chaining $ Take advantage of Chaining $ Apply multiple effects and DOM manipulation @ a time Without Chaining With Chaining $(document).ready(function () { $(document).ready(function () { $('#id').css('color', #143'); $('#id').css('color', $('#id').html(' Request'); #200').html(' Response') $('#id').click(function () { .click(function () { //something //something }); }); }); }); “.css(), .html(…) and more” functions return a jQuery object that can be worked on instantly. So we use it right away to set the other properties like click event handler.
  • 15. DEMO
  • 16. Use Caching $ Caching is a great way to limit the number of times we need to traverse the DOM to find elements matched by the selectors. Without Caching With Caching $(document).ready(function () { $(document).ready(function () { $('#id').css('color', #143'); var id=$('#id'); : id.css('color', #143'); If(isOk) : $('#id').html(' Request'); If(isOk) : id.html(' Request'); If(isEnable) : $('#id').click(function () { If(isEnable) //something id.click(function () { }); }); //something }); });
  • 17. DEMO
  • 18. Click vs Bind vs Live $ Click is to handle click event on element $('#target').click(function() { alert('Handler for .click() called.'); }); $ Bind is used to like same way, to add events. But not only click event. We can create our custom events too. $('#foo').bind('click', function() { $(this).toggleClass('entered'); }); or $('#foo').bind('valid', function() { //Todo}); and we can fire this event like this $(‘#foo’).bind()
  • 19. Click vs Bind vs Live $ Live, will work same like Bind. $ But, Bind can’t add event handler to run time add elements. $ Live will automatically adds handlers for new elements.
  • 20. Event delegation $ Bind handler only once to the parent element containing all the children meant to have handlers. Using Event delegation Normal way $(document).ready(function () { $(document).ready(function () { $('ul').delegate('click', 'li', function (e) { $('ul li').click(function () { // if ($(e.target).is('li')) $(this).toggleClass('hig $(e.target).toggleClass('highlight'); hlight'); }); }); }); }); $ Advantage of this is it will automatically bind click event for new(runtime add) element too.
  • 21. DEMO
  • 22. Minimize DOM manipulation $ We have to minimize DOM operations (.append() .prepend() .after() .wrap() and ..) Without temp variable (full Without temp variable :- DOM):- var myNumbers = $('#Numbers'); var myNumbers = var myString= ''; $('#Numbers'); for (i = 0; i < 1000; i++) { for (i=0; i<1000; i++){ mystring += '<li>Number ' + i + '</li>'; myNumbers.append('Number } ' + i); } myList.html(myNumbers);
  • 23. Minimize DOM manipulation(cont..) $ Use template for array items $ !dea from Microsoft $ jQuery add in documentation $ More http://api.jquery.com/jQuery.template/ $ http://api.jquery.com/jquery.tmpl/
  • 24. DEMO
  • 25. Use $(this) and this $ $(this) is jQuery object $ this is traditional HTML object $(document).ready(function () { $('ul li').click(function () { $(this).toggleClass('highlight'); alert(this.innerHTML); }); });
  • 26. DEMO
  • 27. Use data $ Useful. It allows you to bind data to DOM elements without modifying the DOM. $ For example:- # $("div").data("message", "Done!"); # $("div").data("message"); OR # <div data-error=“Error! :(“>…</div> # $("div").data("error");
  • 28. DEMO