SlideShare ist ein Scribd-Unternehmen logo
1 von 30
jQuery
 It's a library, not a framework.
Speakers
Ryan Smith
Front-end architect with Credera. Focused on good user experience
through well-crafted client side code. Current interests include
HTML5, CSS3, mobile development, and Javascript patterns for
responsive web apps. Geeks out on great coffee, cooking, beautiful
design, and elegant code.

Kenny Rosenberg
Senior consultant with Credera. His focus areas
include front end development (usually with JQuery)
and Java web development (usually with Spring
Framework). He graduated from the University of
Texas with a BBA in Management Information
Systems.
Library vs. Framework
• This is a semantic argument
• Why make a distinction?
• Managing expectations
Library
• A collection of helper methods
• Helps us not reinvent the wheel
• Enables greater consistency,
  readability
• Abstracts away the tedious stuff
Framework
• Implies architecture / structure
• Often driven by patterns considered
  to be "best practice," i.e. MVC
• Designed to save you time by
  employing reasonable defaults
  ("convention over configuration")
Comparison
• Libraries can be more open-ended
  and expressive
• Libraries allow you to learn the API
  as needed
• Frameworks require holistic
  understanding
• Frameworks bring structure to large
  amounts of code
jQuery never claimed to be a
framework




…which means the framework is up to
 you to implement
Why do we use jQuery?
Because this was pretty bad.
<a href=“/something" id="myLink"
         onclick="doSomething()">Click Me</a>


This was a little better.
if (el.addEventListener){ // Mozilla
  el.addEventListener('click', doSomething, false);
} else if (el.attachEvent){ // IE
  el.attachEvent('onclick', doSomething);
}


What a relief.
$("#myLink").click(doSomething);
Why do we use jQuery?
Because this wasn’t much fun.
function doAjax() {
var xmlhttp;
if (window.XMLHttpRequest) {
  xmlhttp=new XMLHttpRequest();
} else { // Support older version of IE
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("theDiv").innerHTML=xmlhttp.response
Text;      }
} xmlhttp.open("GET","shiny.html",true); xmlhttp.send();
}


But this is cake.
$("#theDiv").load("shiny.html");
Why do we use jQuery?
Selectors!
$("#nav li:first > a")
$(":input:not(:checked)")
$("#invoice tr:odd")

• Most browsers have implemented
  native querySelector /
  querySelectorAll, but prior to that,
  complex node selections were
  painful.
jQuery Patterns
• Anonymous functions
• Method chaining
• $(document).ready
• Manipulates references to this
  inside callbacks for convenience
  (i.e. this == the calling DOM
  element in event handlers)
jQuery Plugins
• Easy to write
• Easy to use
• Proliferated rapidly as jQuery
  popularity grew
• Attracts new users and JS novices
  to jQuery
jQuery Plugins

     A Word of Caution
Adopting a plugin is like adopting a
puppy. Know its behavior before
letting it into your home.


Translation: Read the source.
jQuery and Complexity
• jQuery is ideal for most websites
  because of its simple API and
  compact but expressive syntax.
• But what about really large
  websites? Complex web apps?
  Single page web apps?
Possible Pitfalls
• Tightly-coupled code leads to copy
  & paste pattern
• Failure to stay DRY
• Polluted global namespace
• “Pluginitis”
• Reliance on DOM to hold transient
  application state
Recommended Strategies
1. Logical separation of JS into
   loosely-coupled modules
2. Standardized communication
   between modules
3. Separation of model (application
   state) from view (DOM)
Module Pattern
• Douglas Crockford first publicized in
  2007
• We like the “Revealing” variant
  proposed by Christian Heilmann



Sources: http://www.yuiblog.com/blog/2007/06/12/module-pattern/
http://www.wait-till-i.com/2007/08/22/again-with-the-module-pattern-reveal-something-to-the-world/
Anatomy of a Module
                anonymous function
name
                                                    private scope
       var Presentation.sampleModule = function() {
                 //private vars and functions
                 var secretText = "I can't be accessed directly";
                 var moduleDescription = "Revealing module pattern
       example"
                 var getText = function() {
                           return secretText;
                 }
                                                    public scope
                //create a public API by exposing certain members
                return {
                          revealText: getText,
                          about : moduleDescription
                          }
                };
       }();

   self-executing
{ demo }
Pub/Sub
• Publish and Subscribe
• Events replace direct function calls
• Publishers notify the system
• Subscribers listen and act
• Publishers and subscribers don’t
  need to know about each other
Pub/Sub
• Trivial to implement with jQuery
  custom events
 //subscribe
 $(document).bind(“listChanged”, function(e, data) {
        $(“#items”).effect("highlight", {}, 5000);
 });

 //publish
 $(document).trigger(“listChanged”);


• Binding events to the DOM is
  slightly slower than other plugins
Pub/Sub
• Binding events to the DOM with
  bind() and trigger() has a slight
  performance cost.
• For large numbers of events,
  consider a dedicated pub/sub plugin
• Use namespacing for added clarity
  “/some/topic”
{ demo }
Templates
• Sometimes we need to create
  HTML from Javascript data.
• Ever done this?
 productHTML = '<h2>' + name + '</h2>';
     + '<h4><span>' + description + '</span></h4
     + '<p>$' + price + '</p><a href="„
     + detailsUrl + '"><img src="' + thumbnailImgUrl
     + '" alt="' + thumbnailAltTxt + '" /></a>';
Why templates?
• Templates are more powerful and
  elegant than string concatenation
• Usually, server-side templates do
  the heavy lifting
• Demand for highly responsive UIs
  has created a need for client-side
  rendering of data
When to use templates
• Useful when calling 3rd party APIs
  that return JSON
• Async calls that return large
  amounts of repetitive HTML can be
  refactored as JSON + client side
  templates
• User interactions that require
  instant feedback
Current state of JS templates
• Ideally, we would write a single
  template that can be rendered both
  server and client-side
• Systems that support this:
  • Google Closure templates (used
  for Google +)
  • {{ mustache }}
jQuery Templates
• Still in beta
• Developed by Boris Moore, adopted
  as an “official” jQuery plugin in
  October 2010
• Support for conditional logic,
  iteration, nested templates
• No server-side implementation yet
{ demo }
Thanks for attending!
• Questions?

{ Contact Us }

Ryan Smith                 Kenny Rosenberg
rsmith@credera.com         krosenberg@credera.com
    @ryanlsmith                @kennyrosenberg

http://blogs.credera.com

Weitere ähnliche Inhalte

Kürzlich hochgeladen

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Kürzlich hochgeladen (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

jQuery: It's a library, not a framework

  • 1. jQuery It's a library, not a framework.
  • 2. Speakers Ryan Smith Front-end architect with Credera. Focused on good user experience through well-crafted client side code. Current interests include HTML5, CSS3, mobile development, and Javascript patterns for responsive web apps. Geeks out on great coffee, cooking, beautiful design, and elegant code. Kenny Rosenberg Senior consultant with Credera. His focus areas include front end development (usually with JQuery) and Java web development (usually with Spring Framework). He graduated from the University of Texas with a BBA in Management Information Systems.
  • 3. Library vs. Framework • This is a semantic argument • Why make a distinction? • Managing expectations
  • 4. Library • A collection of helper methods • Helps us not reinvent the wheel • Enables greater consistency, readability • Abstracts away the tedious stuff
  • 5. Framework • Implies architecture / structure • Often driven by patterns considered to be "best practice," i.e. MVC • Designed to save you time by employing reasonable defaults ("convention over configuration")
  • 6. Comparison • Libraries can be more open-ended and expressive • Libraries allow you to learn the API as needed • Frameworks require holistic understanding • Frameworks bring structure to large amounts of code
  • 7. jQuery never claimed to be a framework …which means the framework is up to you to implement
  • 8. Why do we use jQuery? Because this was pretty bad. <a href=“/something" id="myLink" onclick="doSomething()">Click Me</a> This was a little better. if (el.addEventListener){ // Mozilla el.addEventListener('click', doSomething, false); } else if (el.attachEvent){ // IE el.attachEvent('onclick', doSomething); } What a relief. $("#myLink").click(doSomething);
  • 9. Why do we use jQuery? Because this wasn’t much fun. function doAjax() { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { // Support older version of IE xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("theDiv").innerHTML=xmlhttp.response Text; } } xmlhttp.open("GET","shiny.html",true); xmlhttp.send(); } But this is cake. $("#theDiv").load("shiny.html");
  • 10. Why do we use jQuery? Selectors! $("#nav li:first > a") $(":input:not(:checked)") $("#invoice tr:odd") • Most browsers have implemented native querySelector / querySelectorAll, but prior to that, complex node selections were painful.
  • 11. jQuery Patterns • Anonymous functions • Method chaining • $(document).ready • Manipulates references to this inside callbacks for convenience (i.e. this == the calling DOM element in event handlers)
  • 12. jQuery Plugins • Easy to write • Easy to use • Proliferated rapidly as jQuery popularity grew • Attracts new users and JS novices to jQuery
  • 13. jQuery Plugins A Word of Caution Adopting a plugin is like adopting a puppy. Know its behavior before letting it into your home. Translation: Read the source.
  • 14. jQuery and Complexity • jQuery is ideal for most websites because of its simple API and compact but expressive syntax. • But what about really large websites? Complex web apps? Single page web apps?
  • 15. Possible Pitfalls • Tightly-coupled code leads to copy & paste pattern • Failure to stay DRY • Polluted global namespace • “Pluginitis” • Reliance on DOM to hold transient application state
  • 16. Recommended Strategies 1. Logical separation of JS into loosely-coupled modules 2. Standardized communication between modules 3. Separation of model (application state) from view (DOM)
  • 17. Module Pattern • Douglas Crockford first publicized in 2007 • We like the “Revealing” variant proposed by Christian Heilmann Sources: http://www.yuiblog.com/blog/2007/06/12/module-pattern/ http://www.wait-till-i.com/2007/08/22/again-with-the-module-pattern-reveal-something-to-the-world/
  • 18. Anatomy of a Module anonymous function name private scope var Presentation.sampleModule = function() { //private vars and functions var secretText = "I can't be accessed directly"; var moduleDescription = "Revealing module pattern example" var getText = function() { return secretText; } public scope //create a public API by exposing certain members return { revealText: getText, about : moduleDescription } }; }(); self-executing
  • 20. Pub/Sub • Publish and Subscribe • Events replace direct function calls • Publishers notify the system • Subscribers listen and act • Publishers and subscribers don’t need to know about each other
  • 21. Pub/Sub • Trivial to implement with jQuery custom events //subscribe $(document).bind(“listChanged”, function(e, data) { $(“#items”).effect("highlight", {}, 5000); }); //publish $(document).trigger(“listChanged”); • Binding events to the DOM is slightly slower than other plugins
  • 22. Pub/Sub • Binding events to the DOM with bind() and trigger() has a slight performance cost. • For large numbers of events, consider a dedicated pub/sub plugin • Use namespacing for added clarity “/some/topic”
  • 24. Templates • Sometimes we need to create HTML from Javascript data. • Ever done this? productHTML = '<h2>' + name + '</h2>'; + '<h4><span>' + description + '</span></h4 + '<p>$' + price + '</p><a href="„ + detailsUrl + '"><img src="' + thumbnailImgUrl + '" alt="' + thumbnailAltTxt + '" /></a>';
  • 25. Why templates? • Templates are more powerful and elegant than string concatenation • Usually, server-side templates do the heavy lifting • Demand for highly responsive UIs has created a need for client-side rendering of data
  • 26. When to use templates • Useful when calling 3rd party APIs that return JSON • Async calls that return large amounts of repetitive HTML can be refactored as JSON + client side templates • User interactions that require instant feedback
  • 27. Current state of JS templates • Ideally, we would write a single template that can be rendered both server and client-side • Systems that support this: • Google Closure templates (used for Google +) • {{ mustache }}
  • 28. jQuery Templates • Still in beta • Developed by Boris Moore, adopted as an “official” jQuery plugin in October 2010 • Support for conditional logic, iteration, nested templates • No server-side implementation yet
  • 30. Thanks for attending! • Questions? { Contact Us } Ryan Smith Kenny Rosenberg rsmith@credera.com krosenberg@credera.com @ryanlsmith @kennyrosenberg http://blogs.credera.com