SlideShare a Scribd company logo
1 of 29
Download to read offline
{ jQuery Quick         Tips
               From @RockingCode


          Slides by @roch_br (Rochester Oliveira)
       Visit us: RockingCode.Com
{*}     So, what is this about?
 It's pretty cool on how we can do crazy things with a few lines of
     jQuery. But sometimes we forget that after those simple statements,
     several functions start. Then, my friend, we can see the difference
     between ordinary Padawans and Jedi Masters.
 Here, we will see a couple of good practices that will help you code
   better and better.
 Hope you like it, and you’ll find more content like this at
   RockingCode.com
{1}


 Don’t use Javascript.
{1}     Don’t use javascript.
 I know it’s pretty strange hearing this from me (who actually does a
    living from this stuff) but yeah, you read it right.
 My point is, if you can do it via CSS with a good browser support,
   forget about javascript.
 Because jQuery's possibilities can seduce us, you have to be smart,
   and cut that cool hover blinking & shaking effect.
{1}   Don’t use javascript.




          Fancy effects with CSS, HTML & Images
{2}

 If you do,
 do it unobtrusive.
{2}     If you do, do it unobtrusive.
 Unobtrusive javascript is an art, actually. Basic functionality has to be
   done with basic HTML, CSS, & Server-Side scripting. Then all
   javascript does, is just comes brighten your work.
 If you disable JS and can't do basic stuff (like see link's content), you've
     done it wrong, my friend.
 Also, you have to keep in mind that your code may not work or even
    worse, may work in a way that you didn’t expect, since we have a lot
    of parsing differences between real browsers and IE.
{2}     If you do, do it unobtrusive.




 Api.jQuery has live search with js enabled, but works without it well.
{3}


 Use pure JavaScript.
{3}      Use pure JavaScript.
 I shall remind you now, little Grasshopper, that jQuery is just one way
    to implement JS.
 It is NOT Javascript itself.
 And many times it isn't even the best way to do things. If you are
   doing simple things, like getting attributes from an element, you'd
   better do ol' JS.
 Before learning any jQuery, be a Master of JS art. For real. It’ll be much
    easier to do better code when you have raw coding alternatives.
{3}      Use pure JavaScript.




Google Doodles could easily be done with jQuery, but ol’ JS is way better.
{4}

 Cache everything
 you can!
{4}     Cache everything you can.
 Every time you call the $(element), jQuery will search DOM tree
   and see what the element is.
 But if your document doesn't change it too often, it'll be way better
   if you store your results inside a simple var, so jQuery will do it
   only once. All you have to do is call it from that var.
 var $body = $(“body”); //starting with $ so I know it’s a jQ object
{4}   Cache everything you can.




          One of your amazing 1WD’s plugins code
{5}

 Chaining is good for
 you.
{5}     Chaining is good for you
 Another good thing you can do for your performance is chaning.
 Well, if you execute operations with jQuery objects in different lines
   [$elem.op1(); $elem.op2(); ] jQuery will call our dear friend $elem
   twice. Even if we are caching it (if you don't, I'll punch you in your
   face!), we can group things like this with a cool method called
   chaining and have a ultra-better-optimized-golden-plus-plus code.
 //bla bla cool stuff here
    $elem.addClass(“ohYeah”).fadeIn(400);
{6}

 Always do readable
 code!
{6}    Always do readable code
 After doing a fancy code, a few days pass, and you decide to change
    something on it. Well, then you notice that your code looks
    more like a new category, “minified production” version, no
    comments, no indentation but no compressing also.
 When you start doing anything just comment what your basic logic
  is. Try to detail some obscure parts and don’t forget that the
  TAB key is there for one reason: So, USE IT.
{6}   Always do readable code




      jQuery source (Development version). Pretty cool, huh?
{7}

 Avoid (too many)
 plugins.
{7}     Avoid (too many) plugins
 We have A LOT of cool plugins out there, but many of them are just
   useless.
 A plugin that does things that you can do with a few lines of code is
    dangerous for performance.
 They add an extra HTTP request and can potentially mess up things
   since you don’t know exactly how things are done with it. Besides,
   you may not need that fancy effect that costs you 15kb and 30s in
   page rendering.
{8}

 Don’t forget about
 mobile devices.
{8}     Don’t forget about mobile devices
 jQuery mobile is getting more and more power. You have to be ready
    for more and more drag & drop instead of hover and clicks.
 Also you have to optimize you code for smaller processing power and
    smaller screens that are usually found in mobiles.
 It's more than just doing responsive things. It's about doing things
     thinking on a whole new platform, a whole new modus operandi,
     and you must figure out what you can do for the best user
     experience.
{8}   Don’t forget about mobile devices




                    Wikipedia mobile is really good.
      Actually we’ll do a plugin with such functionalitty soon 
{9}


 Avoid fancy selectors.
{9}     Avoid fancy selectors
 Id’s are the best performers. Anything else, will just cost you
    precious time.
 Avoid all those non-built-in selectors, like classes, tags, pseudo-
   selectors, and everything else. These are bad, bad guys.
 Specially if you have total control over HTML (like it’s not
   changing every time or even if you’re dealing with dynamically
   generated content).
{ 10 }

   Find() what you
   need.
{ 10 } Find() what you need
  Sizzle (jQuery selector) does pretty much the same thing as you are used to with
      CSS (yeah, Sizzle too), but we have one main difference that you must to
      notice: Performance.
  Look, since Sizzle works from right to left (yeah, opposite of what you're doing
     right now) if you write it this way $(“h1 a”), it will search for every “a”, then
     check if it has a “h1” as an ancestor.
  As you may notice, that’s really bad for performance since you can have a lot of
     a's in your page. So when you need this kind of search, use find() or even
     children(). First, you search for ancestor, then start a new search for your
     element.
  $(“h1”).find(“a”); //get all “h1” and them look for “a” elements
That’s all... Thanks for reading!


                          Slides by @roch_br (Rochester Oliveira)
                      Visit us: RockingCode.Com

More Related Content

What's hot

Dojo: Getting Started Today
Dojo: Getting Started TodayDojo: Getting Started Today
Dojo: Getting Started TodayGabriel Hamilton
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009Remy Sharp
 
Getting the Most Out of jQuery Widgets
Getting the Most Out of jQuery WidgetsGetting the Most Out of jQuery Widgets
Getting the Most Out of jQuery Widgetsvelveeta_512
 
JavaScript DOM Manipulations
JavaScript DOM ManipulationsJavaScript DOM Manipulations
JavaScript DOM ManipulationsYnon Perek
 
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript librariesJazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript librariesSimon Willison
 
[WEB UI BASIC] JavaScript 1탄
[WEB UI BASIC] JavaScript 1탄[WEB UI BASIC] JavaScript 1탄
[WEB UI BASIC] JavaScript 1탄Jae Woo Woo
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2borkweb
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery BasicsKaloyan Kosev
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingDoug Neiner
 
Learning jQuery @ MIT
Learning jQuery @ MITLearning jQuery @ MIT
Learning jQuery @ MITjeresig
 
jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoiddmethvin
 

What's hot (20)

jQuery Introduction
jQuery IntroductionjQuery Introduction
jQuery Introduction
 
Dojo: Getting Started Today
Dojo: Getting Started TodayDojo: Getting Started Today
Dojo: Getting Started Today
 
jQuery
jQueryjQuery
jQuery
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
 
handout-05b
handout-05bhandout-05b
handout-05b
 
Getting the Most Out of jQuery Widgets
Getting the Most Out of jQuery WidgetsGetting the Most Out of jQuery Widgets
Getting the Most Out of jQuery Widgets
 
Ajax3
Ajax3Ajax3
Ajax3
 
jQuery Best Practice
jQuery Best Practice jQuery Best Practice
jQuery Best Practice
 
JavaScript DOM Manipulations
JavaScript DOM ManipulationsJavaScript DOM Manipulations
JavaScript DOM Manipulations
 
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript librariesJazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
 
[WEB UI BASIC] JavaScript 1탄
[WEB UI BASIC] JavaScript 1탄[WEB UI BASIC] JavaScript 1탄
[WEB UI BASIC] JavaScript 1탄
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2
 
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQuery
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery Basics
 
jQuery
jQueryjQuery
jQuery
 
J query intro_29thsep_alok
J query intro_29thsep_alokJ query intro_29thsep_alok
J query intro_29thsep_alok
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and Bling
 
Cucumber
CucumberCucumber
Cucumber
 
Learning jQuery @ MIT
Learning jQuery @ MITLearning jQuery @ MIT
Learning jQuery @ MIT
 
jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoid
 

Similar to jQuery quick tips

Using Web Services with JavaScript - Fronttrends 2010
Using Web Services with JavaScript - Fronttrends 2010Using Web Services with JavaScript - Fronttrends 2010
Using Web Services with JavaScript - Fronttrends 2010Christian Heilmann
 
Intro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate JavascriptIntro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate JavascriptAndrew Lovett-Barron
 
Everything You Need to Know in Order to Start Using jQuery
Everything You Need to Know in Order to Start Using jQueryEverything You Need to Know in Order to Start Using jQuery
Everything You Need to Know in Order to Start Using jQueryDave Ross
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
Essential Javascript -- A Javascript <b>Tutorial</b>
Essential Javascript -- A Javascript <b>Tutorial</b>Essential Javascript -- A Javascript <b>Tutorial</b>
Essential Javascript -- A Javascript <b>Tutorial</b>tutorialsruby
 
Essential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_TutorialEssential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_Tutorialtutorialsruby
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />tutorialsruby
 
Essential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_TutorialEssential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_Tutorialtutorialsruby
 
Lesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ayLesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ayCodecademy Ren
 
JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4alexsaves
 
Building with JavaScript - write less by using the right tools
Building with JavaScript -  write less by using the right toolsBuilding with JavaScript -  write less by using the right tools
Building with JavaScript - write less by using the right toolsChristian Heilmann
 
The State of Front-end At CrowdTwist
The State of Front-end At CrowdTwistThe State of Front-end At CrowdTwist
The State of Front-end At CrowdTwistMark Fayngersh
 
Your java script library
Your java script libraryYour java script library
Your java script libraryjasfog
 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptjasonsich
 
#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..
#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..
#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..Mark Rackley
 

Similar to jQuery quick tips (20)

Using Web Services with JavaScript - Fronttrends 2010
Using Web Services with JavaScript - Fronttrends 2010Using Web Services with JavaScript - Fronttrends 2010
Using Web Services with JavaScript - Fronttrends 2010
 
Intro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate JavascriptIntro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate Javascript
 
Everything You Need to Know in Order to Start Using jQuery
Everything You Need to Know in Order to Start Using jQueryEverything You Need to Know in Order to Start Using jQuery
Everything You Need to Know in Order to Start Using jQuery
 
Fewd week4 slides
Fewd week4 slidesFewd week4 slides
Fewd week4 slides
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
All of Javascript
All of JavascriptAll of Javascript
All of Javascript
 
Essential Javascript -- A Javascript <b>Tutorial</b>
Essential Javascript -- A Javascript <b>Tutorial</b>Essential Javascript -- A Javascript <b>Tutorial</b>
Essential Javascript -- A Javascript <b>Tutorial</b>
 
Essential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_TutorialEssential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_Tutorial
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 
Essential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_TutorialEssential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_Tutorial
 
Lesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ayLesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ay
 
Jquery
JqueryJquery
Jquery
 
JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4
 
Building with JavaScript - write less by using the right tools
Building with JavaScript -  write less by using the right toolsBuilding with JavaScript -  write less by using the right tools
Building with JavaScript - write less by using the right tools
 
The State of Front-end At CrowdTwist
The State of Front-end At CrowdTwistThe State of Front-end At CrowdTwist
The State of Front-end At CrowdTwist
 
Your java script library
Your java script libraryYour java script library
Your java script library
 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScript
 
#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..
#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..
#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..
 
Shifting Gears
Shifting GearsShifting Gears
Shifting Gears
 
J Query
J QueryJ Query
J Query
 

Recently uploaded

Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Recently uploaded (20)

Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

jQuery quick tips

  • 1. { jQuery Quick Tips From @RockingCode Slides by @roch_br (Rochester Oliveira) Visit us: RockingCode.Com
  • 2. {*} So, what is this about? It's pretty cool on how we can do crazy things with a few lines of jQuery. But sometimes we forget that after those simple statements, several functions start. Then, my friend, we can see the difference between ordinary Padawans and Jedi Masters. Here, we will see a couple of good practices that will help you code better and better. Hope you like it, and you’ll find more content like this at RockingCode.com
  • 3. {1} Don’t use Javascript.
  • 4. {1} Don’t use javascript. I know it’s pretty strange hearing this from me (who actually does a living from this stuff) but yeah, you read it right. My point is, if you can do it via CSS with a good browser support, forget about javascript. Because jQuery's possibilities can seduce us, you have to be smart, and cut that cool hover blinking & shaking effect.
  • 5. {1} Don’t use javascript. Fancy effects with CSS, HTML & Images
  • 6. {2} If you do, do it unobtrusive.
  • 7. {2} If you do, do it unobtrusive. Unobtrusive javascript is an art, actually. Basic functionality has to be done with basic HTML, CSS, & Server-Side scripting. Then all javascript does, is just comes brighten your work. If you disable JS and can't do basic stuff (like see link's content), you've done it wrong, my friend. Also, you have to keep in mind that your code may not work or even worse, may work in a way that you didn’t expect, since we have a lot of parsing differences between real browsers and IE.
  • 8. {2} If you do, do it unobtrusive. Api.jQuery has live search with js enabled, but works without it well.
  • 9. {3} Use pure JavaScript.
  • 10. {3} Use pure JavaScript. I shall remind you now, little Grasshopper, that jQuery is just one way to implement JS. It is NOT Javascript itself. And many times it isn't even the best way to do things. If you are doing simple things, like getting attributes from an element, you'd better do ol' JS. Before learning any jQuery, be a Master of JS art. For real. It’ll be much easier to do better code when you have raw coding alternatives.
  • 11. {3} Use pure JavaScript. Google Doodles could easily be done with jQuery, but ol’ JS is way better.
  • 13. {4} Cache everything you can. Every time you call the $(element), jQuery will search DOM tree and see what the element is. But if your document doesn't change it too often, it'll be way better if you store your results inside a simple var, so jQuery will do it only once. All you have to do is call it from that var. var $body = $(“body”); //starting with $ so I know it’s a jQ object
  • 14. {4} Cache everything you can. One of your amazing 1WD’s plugins code
  • 15. {5} Chaining is good for you.
  • 16. {5} Chaining is good for you Another good thing you can do for your performance is chaning. Well, if you execute operations with jQuery objects in different lines [$elem.op1(); $elem.op2(); ] jQuery will call our dear friend $elem twice. Even if we are caching it (if you don't, I'll punch you in your face!), we can group things like this with a cool method called chaining and have a ultra-better-optimized-golden-plus-plus code. //bla bla cool stuff here $elem.addClass(“ohYeah”).fadeIn(400);
  • 17. {6} Always do readable code!
  • 18. {6} Always do readable code After doing a fancy code, a few days pass, and you decide to change something on it. Well, then you notice that your code looks more like a new category, “minified production” version, no comments, no indentation but no compressing also. When you start doing anything just comment what your basic logic is. Try to detail some obscure parts and don’t forget that the TAB key is there for one reason: So, USE IT.
  • 19. {6} Always do readable code jQuery source (Development version). Pretty cool, huh?
  • 20. {7} Avoid (too many) plugins.
  • 21. {7} Avoid (too many) plugins We have A LOT of cool plugins out there, but many of them are just useless. A plugin that does things that you can do with a few lines of code is dangerous for performance. They add an extra HTTP request and can potentially mess up things since you don’t know exactly how things are done with it. Besides, you may not need that fancy effect that costs you 15kb and 30s in page rendering.
  • 22. {8} Don’t forget about mobile devices.
  • 23. {8} Don’t forget about mobile devices jQuery mobile is getting more and more power. You have to be ready for more and more drag & drop instead of hover and clicks. Also you have to optimize you code for smaller processing power and smaller screens that are usually found in mobiles. It's more than just doing responsive things. It's about doing things thinking on a whole new platform, a whole new modus operandi, and you must figure out what you can do for the best user experience.
  • 24. {8} Don’t forget about mobile devices Wikipedia mobile is really good. Actually we’ll do a plugin with such functionalitty soon 
  • 25. {9} Avoid fancy selectors.
  • 26. {9} Avoid fancy selectors Id’s are the best performers. Anything else, will just cost you precious time. Avoid all those non-built-in selectors, like classes, tags, pseudo- selectors, and everything else. These are bad, bad guys. Specially if you have total control over HTML (like it’s not changing every time or even if you’re dealing with dynamically generated content).
  • 27. { 10 } Find() what you need.
  • 28. { 10 } Find() what you need Sizzle (jQuery selector) does pretty much the same thing as you are used to with CSS (yeah, Sizzle too), but we have one main difference that you must to notice: Performance. Look, since Sizzle works from right to left (yeah, opposite of what you're doing right now) if you write it this way $(“h1 a”), it will search for every “a”, then check if it has a “h1” as an ancestor. As you may notice, that’s really bad for performance since you can have a lot of a's in your page. So when you need this kind of search, use find() or even children(). First, you search for ancestor, then start a new search for your element. $(“h1”).find(“a”); //get all “h1” and them look for “a” elements
  • 29. That’s all... Thanks for reading! Slides by @roch_br (Rochester Oliveira) Visit us: RockingCode.Com