SlideShare una empresa de Scribd logo
1 de 31
Descargar para leer sin conexión
Ditching JQuery
Hao Luo
Northwestern University
https://joind.in/13726
Ditching JQuery - Hao Luo - php[tek] 2015
Intro
2
4 years as a full-time web developer
Ditching JQuery - Hao Luo - php[tek] 2015
I ❤ JQuery
•One codebase, all the browser!
•Introduced me to JavaScript
•“It just works”
3
Ditching JQuery - Hao Luo - php[tek] 2015
Goal of This Talk
•Not to convince anyone
•Important to understand the basics
•Lessen the hurdle to start using pure JavaScript
4
Ditching JQuery - Hao Luo - php[tek] 20155
Scenario Problem
Ditching JQuery - Hao Luo - php[tek] 2015
Our Late Stay Requirements
Admin can…
•See a list of applications with some information
•Can decide to approve or deny an application
•Can delete an application
•Can add a random application
6
Ditching JQuery - Hao Luo - php[tek] 2015
IE9 Demo
7
latestayapp.com/jquery
latestayapp.com/purejs
Ditching JQuery - Hao Luo - php[tek] 2015
Late Stay Workflow
8
HTTP GET latestayapp.com/purejs
HTML (empty ul#applications container)
AJAX GET latestayapp.com/applications
JSON (parses then inserts in #applications container)
(admin clicks on the approve button)
AJAX PUT latestayapp.com/applications/20/approve
JSON (update HTML)
AJAX
DOM
Events
Ditching JQuery - Hao Luo - php[tek] 2015
DOM
Querying, Traversal, and Manipulation
9
Ditching JQuery - Hao Luo - php[tek] 2015
Some DOM Operations
10
JQuery Vanilla JS
$(‘#application-­‐20’); document.querySelector(‘#application-­‐20’);
$el.attr(‘data-­‐id’,	
  ‘20’);	
  
$el.attr(‘data-­‐id’);
el.setAttribute(‘data-­‐id’,	
  ‘20’);	
  
el.getAttribute(‘data-­‐id’);
yes yes yes 9+
yes yes yes yes
yes yes yes 10+$el.addClass(‘approved’);	
  
$el.removeClass(‘approved’);	
  
$el.toggleClass(‘approved’);
el.classList.add(‘approved’);	
  
el.classList.remove(‘approved’);	
  
el.classList.toggle(‘approved’);
$el.data(‘id’,	
  ‘20’);	
  
var	
  id	
  =	
  $el.data(‘id’);
el.dataset.id	
  =	
  ‘20’;	
  
var	
  id	
  =	
  el.dataset.id; yes yes yes 11+
$button.closest(‘.application’); button.closest(‘.application’); 41 35 no no
https://dom.spec.whatwg.org/#dom-element-closestselectors
https://github.com/eligrey/classList.js/
Ditching JQuery - Hao Luo - php[tek] 2015
Polyfills
11
A polyfill is a piece of code that provides the technology that the developer expects the
browser to provide natively. Flattening the API landscape if you will. - Remy Sharp
var	
  ELEMENT	
  =	
  Element.prototype;	
  
ELEMENT.matches	
  =	
  ELEMENT.matches	
  
	
  	
  	
  	
  ||	
  ELEMENT.msMatchesSelector	
  
	
  	
  	
  	
  ||	
  ELEMENT.mozMatchesSelector	
  
	
  	
  	
  	
  ||	
  ELEMENT.webkitMatchesSelector;	
  
ELEMENT.closest	
  =	
  ELEMENT.closest	
  	
  
	
  	
  	
  	
  ||	
  function	
  (selector)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  var	
  node	
  =	
  this;	
  
	
  	
  	
  	
  	
  	
  	
  	
  while	
  (node)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  if	
  (node.matches(selector))	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  break;	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  node	
  =	
  node.parentElement;	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  	
  	
  	
  	
  return	
  node;	
  
};	
  
41 35 no no
yes yes yes 9+
<li	
  class="application"	
  id=“#application-­‐20">	
  
…	
  
	
  	
  	
  	
  <div	
  class="action-­‐bar">	
  
	
  	
  	
  	
  	
  	
  	
  	
  <div	
  class=“action">	
  
…	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  <button	
  class="delete">	
  
	
  	
  	
  	
  	
  	
  	
  	
  </div>	
  
	
  	
  	
  	
  </div>	
  
</li>	
  
deleteButton.closest('.application');	
  
HTML
Javascript
Javascript
Ditching JQuery - Hao Luo - php[tek] 2015
DOM Events
12
Ditching JQuery - Hao Luo - php[tek] 201513
Register Event Callbacks Yes Yes Yes 9+
JQuery $('.delete').on('click',	
  deleteApplication);
Vanilla JS
getAllElToArr('.delete').forEach(function	
  (el)	
  {	
  
	
  	
  	
  el.addEventListener('click',	
  deleteApplication);	
  
});	
  
Ditching JQuery - Hao Luo - php[tek] 2015
Direct Events (vs Delegated Events)
14
li.application
li.application
li.application
div#application-container
ul#applications
li.application
li.application ☺☹ ✖
JQuery
$('.delete').on('click',	
  deleteApplication);	
  
Vanilla JS
getAllElToArr('.delete').forEach(function	
  (el)	
  {	
  
	
  	
  	
  el.addEventListener('click',	
  deleteApplication);	
  
});	
  
EventListener #1
EventListener #4
EventListener #3
EventListener #2
EventListener #5
li.application ☺☹ ✖
EventListener #6
✖
✖
✖
✖
Ditching JQuery - Hao Luo - php[tek] 2015
Delegated Events
15
li.application
li.application
li.application
div#application-container
ul#applications
li.application
li.application ☺☹ ✖li.application ☺☹ ✖
JQuery
$(‘ul.applications’).on(‘click’,	
  ‘.deleteBtn’,	
  
deleteApplication);
Vanilla JS No	
  Standard	
  for	
  Event	
  Delegation	
  :(✖
✖
✖
✖
EventListener #1
is the ‘click’ target element the ‘.delete’ button? 

if so, run deleteApplication
is the ‘click’ target element the ‘.approve’ button? 

if so, run approveApplication
https://github.com/ftlabs/ftdomdelegate
Ditching JQuery - Hao Luo - php[tek] 2015
AJAX
16
Ditching JQuery - Hao Luo - php[tek] 2015
AJAX
17
JQuery $.ajax();
Vanilla JS XMLHttpRequest
HTML5 Fetch	
  API
yes yes yes yes
41 no no no
Fetch API Polyfill: https://github.com/github/fetch
yes yes yes 9+
Ditching JQuery - Hao Luo - php[tek] 2015
POST - A Closer Look
18
JQuery XMLHttpRequest
$.ajax('/applications',	
  {	
  
	
  	
  method:	
  'POST',	
  
	
  	
  contentType:	
  'application/json',	
  
	
  	
  processData:	
  false,	
  
	
  	
  data:	
  JSON.stringify({	
  
	
  	
  	
  	
  	
  	
  name:	
  'Joe	
  Bob',	
  
	
  	
  	
  	
  	
  	
  reason:	
  'Too	
  cold	
  outside'	
  
	
  	
  })	
  
})	
  
.then(function	
  success(application)	
  {	
  
	
  	
  appendApplicationHTML(application);	
  
})	
  
.fail(function	
  failed()	
  {	
  
	
  	
  console.log('request	
  failed!');	
  
});	
  
xhr	
  =	
  new	
  XMLHttpRequest();	
  
xhr.open('POST',	
  '/applications'));	
  
xhr.setRequestHeader('Content-­‐Type',	
  'application/json');	
  
xhr.onload	
  =	
  function()	
  {	
  
	
  	
  	
  	
  if	
  (xhr.status	
  ===	
  200)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  var	
  applicationInfo	
  =	
  JSON.parse(xhr.responseText);	
  
	
  	
  	
  	
  	
  	
  appendApplicationHTML(application);	
  
	
  	
  	
  	
  }	
  
	
  	
  	
  	
  else	
  if	
  (xhr.status	
  !==	
  200)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  alert('Request	
  failed.	
  ');	
  
	
  	
  	
  	
  }	
  
};	
  
xhr.send(JSON.stringify({	
  
	
  	
  	
  	
  name:	
  'Joe	
  Bob',	
  
	
  	
  	
  	
  reason:	
  'Too	
  cold	
  outside'	
  
});	
  
Ditching JQuery - Hao Luo - php[tek] 2015
POST - A Closer Look
19
JQuery Fetch API
$.ajax('/applications',	
  {	
  
	
  	
  method:	
  'POST',	
  
	
  	
  contentType:	
  'application/json',	
  
	
  	
  processData:	
  false,	
  
	
  	
  data:	
  JSON.stringify({	
  
	
  	
  	
  	
  	
  	
  name:	
  'Joe	
  Bob',	
  
	
  	
  	
  	
  	
  	
  reason:	
  'Too	
  cold	
  outside'	
  
	
  	
  })	
  
})	
  
.then(function	
  success(application)	
  {	
  
	
  	
  appendApplicationHTML(application);	
  
})	
  
.fail(function	
  failed()	
  {	
  
	
  	
  console.log('request	
  failed!');	
  
});	
  
fetch('/users',	
  {	
  
	
  	
  method:	
  'post',	
  
	
  	
  headers:	
  {	
  
	
  	
  	
  	
  'Content-­‐Type':	
  'application/json'	
  
	
  	
  },	
  
	
  	
  body:	
  JSON.stringify({	
  
	
  	
  	
  	
  name:	
  'Joe	
  Bob',	
  
	
  	
  	
  	
  reason:	
  'Too	
  Cold	
  Outside'	
  
	
  	
  })	
  
})	
  
.then(function	
  (response)	
  {	
  
	
  	
  return	
  response.json();	
  
})	
  
.then(function	
  (application)	
  {	
  
	
  	
  appendApplicationHTML(application);	
  
})	
  
.catch(function(error)	
  {	
  
	
  	
  console.log('request	
  failed',	
  error);	
  
});	
  
Ditching JQuery - Hao Luo - php[tek] 2015
Eliminates Callback hell
Offers More Flexibility and Freedom
Promises are awesome
20
Ditching JQuery - Hao Luo - php[tek] 2015
Utilities
21
Ditching JQuery - Hao Luo - php[tek] 2015
DOM Loaded
22
JQuery Vanilla JS
$(function(event)	
  {	
  
	
  	
  console.log("DOM	
  fully	
  loaded	
  and	
  parsed");	
  
});	
  
document.addEventListener("DOMContentLoaded",	
  
function(event)	
  {	
  
	
  	
  	
  	
  console.log("DOM	
  fully	
  loaded	
  and	
  parsed");	
  
	
  	
  });	
  
yes yes yes 9+
Don’t use "load"
Ditching JQuery - Hao Luo - php[tek] 2015
HTML Parse
23
JQuery Vanilla JS
var	
  el	
  =	
  $.parseHTML(HTMLString);
var	
  parser	
  =	
  new	
  DOMParser();	
  	
  
var	
  doc	
  =	
  parser.parseFromString(HTMLString,	
  'text/html');	
  	
  
var	
  el	
  =	
  doc.body.firstChild;	
  
30 12 7.1 10+
function	
  parseHTML	
  (str)	
  {	
  
	
  	
  var	
  tmp	
  =	
  document.implementation.createHTMLDocument('');	
  
	
  	
  tmp.body.innerHTML	
  =	
  str;	
  
	
  	
  return	
  tmp.body.firstChild;	
  
};	
  
IE9 won’t accept empty param
yes yes yes 9+
Ditching JQuery - Hao Luo - php[tek] 2015
Date Parse
IE9 needs W3C output (which is also ISO 8601
compliant) (http://www.w3.org/TR/NOTE-
datetime-970915.html)
24
<?php	
  
$objDateTime	
  =	
  new	
  DateTime('NOW');	
  
echo	
  $objDateTime-­‐>format('c');	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  //	
  1975-­‐12-­‐25T14:15:16-­‐05:00	
  Yes	
  IE9	
  
echo	
  $objDateTime-­‐>format(DateTime::ISO8601);	
  //	
  1975-­‐12-­‐25T14:15:16-­‐0500	
  	
  No	
  IE9	
  
Ditching JQuery - Hao Luo - php[tek] 2015
A word about JQuery Animate
•Use Semantic HTML
•Use CSS Transition
25
.application	
  {	
  
	
  	
  	
  	
  opacity:	
  1;	
  
	
  	
  	
  	
  max-­‐height:	
  300px;	
  
	
  	
  	
  	
  transition:	
  max-­‐height	
  0.5s,	
  opacity	
  0.7s;	
  
}	
  
.application.removed	
  {	
  
	
  	
  	
  	
  max-­‐height:	
  0;	
  
	
  	
  	
  	
  opacity:	
  0;	
  
}	
  
CSS
Ditching JQuery - Hao Luo - php[tek] 2015
Closing Thoughts
26
Ditching JQuery - Hao Luo - php[tek] 201527
Non-Technical Reasons
• a lot of magic is confusing sometimes
• Understanding the basics makes you a better
developer
$('div');	
  //creates	
  a	
  jquery	
  instance	
  with	
  the	
  selection	
  inside	
  
$('<div>');	
  //creates	
  a	
  jquery	
  instance	
  with	
  a	
  new	
  element	
  not	
  in	
  document	
  
$($aJQueryInstance);	
  //makes	
  a	
  clone	
  of	
  $aJQueryInstance	
  
$(function()	
  {})	
  //registers	
  function	
  to	
  run	
  after	
  DOM	
  is	
  loaded	
  
$({foo:	
  'bar'});	
  //???	
  creates	
  a	
  jquery	
  set	
  that	
  has	
  a	
  subset	
  of	
  methods	
  ???	
  
var	
  $appsEl1	
  =	
  $('#applications');	
  
var	
  $appsEl2	
  =	
  $('#applications');	
  
$appsEl1	
  ===	
  $appsEl2;	
  //false	
  
var	
  appsEl1	
  =	
  document.querySelector('#applications');	
  
var	
  appsEl2	
  =	
  document.querySelector('#applications');	
  
appsEl1	
  ===	
  appsEl2;	
  //true	
  
Ditching JQuery - Hao Luo - php[tek] 2015
Some Takeaways
•Use Packages and Polyfills vs monolithic libraries &
frameworks
•Out of the JQuery Plugin Ecosystem and into NPM or
Bower
•Browser and Server
28
Ditching JQuery - Hao Luo - php[tek] 2015
When to use JQuery
•When you have to support IE8
•When you don’t have CORS
•Abstractions sometimes are good!
29
uses requestAnimationFrames	
  for	
  its	
  animationsuses setInterval	
  for	
  its	
  animations
Ditching JQuery - Hao Luo - php[tek] 2015
Resources for DOM references
http://blog.garstasio.com/you-dont-need-jquery/
http://youmightnotneedjquery.com/
http://html5please.com/
30
Ditching JQuery - Hao Luo - php[tek] 2015
Thank you!
@howlowck
https://joind.in/13726
31

Más contenido relacionado

La actualidad más candente

JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)Nicholas Zakas
 
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...Iakiv Kramarenko
 
Introductionandgreetings
IntroductionandgreetingsIntroductionandgreetings
IntroductionandgreetingsPozz ZaRat
 
Writing JavaScript that doesn't suck
Writing JavaScript that doesn't suckWriting JavaScript that doesn't suck
Writing JavaScript that doesn't suckRoss Bruniges
 
The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it meansRobert Nyman
 
Introducing Vuex in your project
Introducing Vuex in your projectIntroducing Vuex in your project
Introducing Vuex in your projectDenny Biasiolli
 
You do not need automation engineer - Sqa Days - 2015 - EN
You do not need automation engineer  - Sqa Days - 2015 - ENYou do not need automation engineer  - Sqa Days - 2015 - EN
You do not need automation engineer - Sqa Days - 2015 - ENIakiv Kramarenko
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Michelangelo van Dam
 
amsterdamjs - jQuery 1.5
amsterdamjs - jQuery 1.5amsterdamjs - jQuery 1.5
amsterdamjs - jQuery 1.5mennovanslooten
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projectsIgnacio Martín
 
Page Objects Done Right - selenium conference 2014
Page Objects Done Right - selenium conference 2014Page Objects Done Right - selenium conference 2014
Page Objects Done Right - selenium conference 2014Oren Rubin
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KThomas Fuchs
 
04 Advanced Javascript
04 Advanced Javascript04 Advanced Javascript
04 Advanced Javascriptcrgwbr
 
A Journey with React
A Journey with ReactA Journey with React
A Journey with ReactFITC
 
My Top 5 APEX JavaScript API's
My Top 5 APEX JavaScript API'sMy Top 5 APEX JavaScript API's
My Top 5 APEX JavaScript API'sRoel Hartman
 
Avinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPressAvinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPresswpnepal
 

La actualidad más candente (20)

JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)
 
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
 
JavaScript Promise
JavaScript PromiseJavaScript Promise
JavaScript Promise
 
Introductionandgreetings
IntroductionandgreetingsIntroductionandgreetings
Introductionandgreetings
 
Promise pattern
Promise patternPromise pattern
Promise pattern
 
Writing JavaScript that doesn't suck
Writing JavaScript that doesn't suckWriting JavaScript that doesn't suck
Writing JavaScript that doesn't suck
 
The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it means
 
Introducing Vuex in your project
Introducing Vuex in your projectIntroducing Vuex in your project
Introducing Vuex in your project
 
You do not need automation engineer - Sqa Days - 2015 - EN
You do not need automation engineer  - Sqa Days - 2015 - ENYou do not need automation engineer  - Sqa Days - 2015 - EN
You do not need automation engineer - Sqa Days - 2015 - EN
 
Framework
FrameworkFramework
Framework
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
amsterdamjs - jQuery 1.5
amsterdamjs - jQuery 1.5amsterdamjs - jQuery 1.5
amsterdamjs - jQuery 1.5
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
 
Page Objects Done Right - selenium conference 2014
Page Objects Done Right - selenium conference 2014Page Objects Done Right - selenium conference 2014
Page Objects Done Right - selenium conference 2014
 
Event source everything!
Event source everything!Event source everything!
Event source everything!
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
 
04 Advanced Javascript
04 Advanced Javascript04 Advanced Javascript
04 Advanced Javascript
 
A Journey with React
A Journey with ReactA Journey with React
A Journey with React
 
My Top 5 APEX JavaScript API's
My Top 5 APEX JavaScript API'sMy Top 5 APEX JavaScript API's
My Top 5 APEX JavaScript API's
 
Avinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPressAvinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPress
 

Destacado

Abusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side StorageAbusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side Storageameft
 
Unpolished Rice - Panacea for Good Health
Unpolished Rice - Panacea for Good HealthUnpolished Rice - Panacea for Good Health
Unpolished Rice - Panacea for Good Healthgloherbals
 
Fuzzing Techniques for Software Vulnerability Discovery
Fuzzing Techniques for Software Vulnerability DiscoveryFuzzing Techniques for Software Vulnerability Discovery
Fuzzing Techniques for Software Vulnerability Discoveryameft
 
Constipation and its Remedy
Constipation and its RemedyConstipation and its Remedy
Constipation and its Remedyzegensocial
 
Mobi sir presentation
Mobi sir presentationMobi sir presentation
Mobi sir presentationG Srinivasan
 
Pt Kinhamas Abadi Company Profile
Pt Kinhamas Abadi    Company ProfilePt Kinhamas Abadi    Company Profile
Pt Kinhamas Abadi Company ProfileHabibie Razak
 
Experiments around Mobile Learning
Experiments around Mobile LearningExperiments around Mobile Learning
Experiments around Mobile LearningG Srinivasan
 
ArthaVidhya brochure
ArthaVidhya brochureArthaVidhya brochure
ArthaVidhya brochureG Srinivasan
 
The Social Media Spine: Building the backbone to your online presence
The Social Media Spine: Building the backbone to your online presenceThe Social Media Spine: Building the backbone to your online presence
The Social Media Spine: Building the backbone to your online presenceStacy Lukasavitz Steele
 
Lost at sea? Location-based services to the rescue!
Lost at sea? Location-based services to the rescue! Lost at sea? Location-based services to the rescue!
Lost at sea? Location-based services to the rescue! Stacy Lukasavitz Steele
 
A guru always takes you for a ride sadhguru
A guru always takes you for a ride sadhguruA guru always takes you for a ride sadhguru
A guru always takes you for a ride sadhgururegstuff
 
548510 sap-release-strategy
548510 sap-release-strategy548510 sap-release-strategy
548510 sap-release-strategysanteetax
 
Vasudhara dairy case study
Vasudhara dairy case studyVasudhara dairy case study
Vasudhara dairy case studyalishashah155
 
Cow and Our Health
Cow  and Our HealthCow  and Our Health
Cow and Our Healthzegensocial
 
Managing Environmental Project at PT Inco; Actualization of Professional Ethi...
Managing Environmental Project at PT Inco; Actualization of Professional Ethi...Managing Environmental Project at PT Inco; Actualization of Professional Ethi...
Managing Environmental Project at PT Inco; Actualization of Professional Ethi...Habibie Razak
 
Power point Presentation on SEVAI - COW PROJECT, .
Power point Presentation on SEVAI - COW PROJECT, .Power point Presentation on SEVAI - COW PROJECT, .
Power point Presentation on SEVAI - COW PROJECT, .sevaingo
 
Basic Funding Concepts for Entrepreneurs
Basic Funding Concepts for EntrepreneursBasic Funding Concepts for Entrepreneurs
Basic Funding Concepts for EntrepreneursAlok Rodinhood Kejriwal
 
How to grow taller 4 idiots pdf
How to grow taller 4 idiots pdfHow to grow taller 4 idiots pdf
How to grow taller 4 idiots pdfmrmicky368
 
Building a Marketplace: A Checklist for Online Disruption
Building a Marketplace: A Checklist for Online DisruptionBuilding a Marketplace: A Checklist for Online Disruption
Building a Marketplace: A Checklist for Online DisruptionSangeet Paul Choudary
 

Destacado (20)

Abusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side StorageAbusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side Storage
 
Unpolished Rice - Panacea for Good Health
Unpolished Rice - Panacea for Good HealthUnpolished Rice - Panacea for Good Health
Unpolished Rice - Panacea for Good Health
 
Fuzzing Techniques for Software Vulnerability Discovery
Fuzzing Techniques for Software Vulnerability DiscoveryFuzzing Techniques for Software Vulnerability Discovery
Fuzzing Techniques for Software Vulnerability Discovery
 
Constipation and its Remedy
Constipation and its RemedyConstipation and its Remedy
Constipation and its Remedy
 
Mobi sir presentation
Mobi sir presentationMobi sir presentation
Mobi sir presentation
 
Pt Kinhamas Abadi Company Profile
Pt Kinhamas Abadi    Company ProfilePt Kinhamas Abadi    Company Profile
Pt Kinhamas Abadi Company Profile
 
Experiments around Mobile Learning
Experiments around Mobile LearningExperiments around Mobile Learning
Experiments around Mobile Learning
 
Upavaasa Yoga
Upavaasa YogaUpavaasa Yoga
Upavaasa Yoga
 
ArthaVidhya brochure
ArthaVidhya brochureArthaVidhya brochure
ArthaVidhya brochure
 
The Social Media Spine: Building the backbone to your online presence
The Social Media Spine: Building the backbone to your online presenceThe Social Media Spine: Building the backbone to your online presence
The Social Media Spine: Building the backbone to your online presence
 
Lost at sea? Location-based services to the rescue!
Lost at sea? Location-based services to the rescue! Lost at sea? Location-based services to the rescue!
Lost at sea? Location-based services to the rescue!
 
A guru always takes you for a ride sadhguru
A guru always takes you for a ride sadhguruA guru always takes you for a ride sadhguru
A guru always takes you for a ride sadhguru
 
548510 sap-release-strategy
548510 sap-release-strategy548510 sap-release-strategy
548510 sap-release-strategy
 
Vasudhara dairy case study
Vasudhara dairy case studyVasudhara dairy case study
Vasudhara dairy case study
 
Cow and Our Health
Cow  and Our HealthCow  and Our Health
Cow and Our Health
 
Managing Environmental Project at PT Inco; Actualization of Professional Ethi...
Managing Environmental Project at PT Inco; Actualization of Professional Ethi...Managing Environmental Project at PT Inco; Actualization of Professional Ethi...
Managing Environmental Project at PT Inco; Actualization of Professional Ethi...
 
Power point Presentation on SEVAI - COW PROJECT, .
Power point Presentation on SEVAI - COW PROJECT, .Power point Presentation on SEVAI - COW PROJECT, .
Power point Presentation on SEVAI - COW PROJECT, .
 
Basic Funding Concepts for Entrepreneurs
Basic Funding Concepts for EntrepreneursBasic Funding Concepts for Entrepreneurs
Basic Funding Concepts for Entrepreneurs
 
How to grow taller 4 idiots pdf
How to grow taller 4 idiots pdfHow to grow taller 4 idiots pdf
How to grow taller 4 idiots pdf
 
Building a Marketplace: A Checklist for Online Disruption
Building a Marketplace: A Checklist for Online DisruptionBuilding a Marketplace: A Checklist for Online Disruption
Building a Marketplace: A Checklist for Online Disruption
 

Similar a Ditching JQuery

jQuery Internals + Cool Stuff
jQuery Internals + Cool StuffjQuery Internals + Cool Stuff
jQuery Internals + Cool Stuffjeresig
 
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 JavaScriptGuy Royse
 
20150516 modern web_conf_tw
20150516 modern web_conf_tw20150516 modern web_conf_tw
20150516 modern web_conf_twTse-Ching Ho
 
Asynchronous Interfaces
Asynchronous InterfacesAsynchronous Interfaces
Asynchronous Interfacesmaccman
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsJeff Durta
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkDirk Haun
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4Javier Eguiluz
 
Automation Abstraction Layers: Page Objects and Beyond
Automation Abstraction Layers: Page Objects and BeyondAutomation Abstraction Layers: Page Objects and Beyond
Automation Abstraction Layers: Page Objects and BeyondAlan Richardson
 
How to write not breakable unit tests
How to write not breakable unit testsHow to write not breakable unit tests
How to write not breakable unit testsRafal Ksiazek
 
Cross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineCross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineAndy McKay
 
OWASP TOP 10 for PHP Programmers
OWASP TOP 10 for PHP ProgrammersOWASP TOP 10 for PHP Programmers
OWASP TOP 10 for PHP Programmersrjsmelo
 

Similar a Ditching JQuery (20)

Frontin like-a-backer
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backer
 
jQuery Internals + Cool Stuff
jQuery Internals + Cool StuffjQuery Internals + Cool Stuff
jQuery Internals + Cool Stuff
 
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
 
20150516 modern web_conf_tw
20150516 modern web_conf_tw20150516 modern web_conf_tw
20150516 modern web_conf_tw
 
Rails is not just Ruby
Rails is not just RubyRails is not just Ruby
Rails is not just Ruby
 
Asynchronous Interfaces
Asynchronous InterfacesAsynchronous Interfaces
Asynchronous Interfaces
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
Advance jquery-plugin
Advance jquery-pluginAdvance jquery-plugin
Advance jquery-plugin
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
 
Automation Abstraction Layers: Page Objects and Beyond
Automation Abstraction Layers: Page Objects and BeyondAutomation Abstraction Layers: Page Objects and Beyond
Automation Abstraction Layers: Page Objects and Beyond
 
J query training
J query trainingJ query training
J query training
 
How to write not breakable unit tests
How to write not breakable unit testsHow to write not breakable unit tests
How to write not breakable unit tests
 
symfony & jQuery (phpDay)
symfony & jQuery (phpDay)symfony & jQuery (phpDay)
symfony & jQuery (phpDay)
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
Cross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineCross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App Engine
 
Dojo and Adobe AIR
Dojo and Adobe AIRDojo and Adobe AIR
Dojo and Adobe AIR
 
OWASP TOP 10 for PHP Programmers
OWASP TOP 10 for PHP ProgrammersOWASP TOP 10 for PHP Programmers
OWASP TOP 10 for PHP Programmers
 

Último

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 

Último (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 

Ditching JQuery

  • 1. Ditching JQuery Hao Luo Northwestern University https://joind.in/13726
  • 2. Ditching JQuery - Hao Luo - php[tek] 2015 Intro 2 4 years as a full-time web developer
  • 3. Ditching JQuery - Hao Luo - php[tek] 2015 I ❤ JQuery •One codebase, all the browser! •Introduced me to JavaScript •“It just works” 3
  • 4. Ditching JQuery - Hao Luo - php[tek] 2015 Goal of This Talk •Not to convince anyone •Important to understand the basics •Lessen the hurdle to start using pure JavaScript 4
  • 5. Ditching JQuery - Hao Luo - php[tek] 20155 Scenario Problem
  • 6. Ditching JQuery - Hao Luo - php[tek] 2015 Our Late Stay Requirements Admin can… •See a list of applications with some information •Can decide to approve or deny an application •Can delete an application •Can add a random application 6
  • 7. Ditching JQuery - Hao Luo - php[tek] 2015 IE9 Demo 7 latestayapp.com/jquery latestayapp.com/purejs
  • 8. Ditching JQuery - Hao Luo - php[tek] 2015 Late Stay Workflow 8 HTTP GET latestayapp.com/purejs HTML (empty ul#applications container) AJAX GET latestayapp.com/applications JSON (parses then inserts in #applications container) (admin clicks on the approve button) AJAX PUT latestayapp.com/applications/20/approve JSON (update HTML) AJAX DOM Events
  • 9. Ditching JQuery - Hao Luo - php[tek] 2015 DOM Querying, Traversal, and Manipulation 9
  • 10. Ditching JQuery - Hao Luo - php[tek] 2015 Some DOM Operations 10 JQuery Vanilla JS $(‘#application-­‐20’); document.querySelector(‘#application-­‐20’); $el.attr(‘data-­‐id’,  ‘20’);   $el.attr(‘data-­‐id’); el.setAttribute(‘data-­‐id’,  ‘20’);   el.getAttribute(‘data-­‐id’); yes yes yes 9+ yes yes yes yes yes yes yes 10+$el.addClass(‘approved’);   $el.removeClass(‘approved’);   $el.toggleClass(‘approved’); el.classList.add(‘approved’);   el.classList.remove(‘approved’);   el.classList.toggle(‘approved’); $el.data(‘id’,  ‘20’);   var  id  =  $el.data(‘id’); el.dataset.id  =  ‘20’;   var  id  =  el.dataset.id; yes yes yes 11+ $button.closest(‘.application’); button.closest(‘.application’); 41 35 no no https://dom.spec.whatwg.org/#dom-element-closestselectors https://github.com/eligrey/classList.js/
  • 11. Ditching JQuery - Hao Luo - php[tek] 2015 Polyfills 11 A polyfill is a piece of code that provides the technology that the developer expects the browser to provide natively. Flattening the API landscape if you will. - Remy Sharp var  ELEMENT  =  Element.prototype;   ELEMENT.matches  =  ELEMENT.matches          ||  ELEMENT.msMatchesSelector          ||  ELEMENT.mozMatchesSelector          ||  ELEMENT.webkitMatchesSelector;   ELEMENT.closest  =  ELEMENT.closest            ||  function  (selector)  {                  var  node  =  this;                  while  (node)  {                          if  (node.matches(selector))  {                                  break;                          }                          node  =  node.parentElement;                  }                  return  node;   };   41 35 no no yes yes yes 9+ <li  class="application"  id=“#application-­‐20">   …          <div  class="action-­‐bar">                  <div  class=“action">   …                          <button  class="delete">                  </div>          </div>   </li>   deleteButton.closest('.application');   HTML Javascript Javascript
  • 12. Ditching JQuery - Hao Luo - php[tek] 2015 DOM Events 12
  • 13. Ditching JQuery - Hao Luo - php[tek] 201513 Register Event Callbacks Yes Yes Yes 9+ JQuery $('.delete').on('click',  deleteApplication); Vanilla JS getAllElToArr('.delete').forEach(function  (el)  {        el.addEventListener('click',  deleteApplication);   });  
  • 14. Ditching JQuery - Hao Luo - php[tek] 2015 Direct Events (vs Delegated Events) 14 li.application li.application li.application div#application-container ul#applications li.application li.application ☺☹ ✖ JQuery $('.delete').on('click',  deleteApplication);   Vanilla JS getAllElToArr('.delete').forEach(function  (el)  {        el.addEventListener('click',  deleteApplication);   });   EventListener #1 EventListener #4 EventListener #3 EventListener #2 EventListener #5 li.application ☺☹ ✖ EventListener #6 ✖ ✖ ✖ ✖
  • 15. Ditching JQuery - Hao Luo - php[tek] 2015 Delegated Events 15 li.application li.application li.application div#application-container ul#applications li.application li.application ☺☹ ✖li.application ☺☹ ✖ JQuery $(‘ul.applications’).on(‘click’,  ‘.deleteBtn’,   deleteApplication); Vanilla JS No  Standard  for  Event  Delegation  :(✖ ✖ ✖ ✖ EventListener #1 is the ‘click’ target element the ‘.delete’ button? if so, run deleteApplication is the ‘click’ target element the ‘.approve’ button? if so, run approveApplication https://github.com/ftlabs/ftdomdelegate
  • 16. Ditching JQuery - Hao Luo - php[tek] 2015 AJAX 16
  • 17. Ditching JQuery - Hao Luo - php[tek] 2015 AJAX 17 JQuery $.ajax(); Vanilla JS XMLHttpRequest HTML5 Fetch  API yes yes yes yes 41 no no no Fetch API Polyfill: https://github.com/github/fetch yes yes yes 9+
  • 18. Ditching JQuery - Hao Luo - php[tek] 2015 POST - A Closer Look 18 JQuery XMLHttpRequest $.ajax('/applications',  {      method:  'POST',      contentType:  'application/json',      processData:  false,      data:  JSON.stringify({              name:  'Joe  Bob',              reason:  'Too  cold  outside'      })   })   .then(function  success(application)  {      appendApplicationHTML(application);   })   .fail(function  failed()  {      console.log('request  failed!');   });   xhr  =  new  XMLHttpRequest();   xhr.open('POST',  '/applications'));   xhr.setRequestHeader('Content-­‐Type',  'application/json');   xhr.onload  =  function()  {          if  (xhr.status  ===  200)  {                    var  applicationInfo  =  JSON.parse(xhr.responseText);              appendApplicationHTML(application);          }          else  if  (xhr.status  !==  200)  {                  alert('Request  failed.  ');          }   };   xhr.send(JSON.stringify({          name:  'Joe  Bob',          reason:  'Too  cold  outside'   });  
  • 19. Ditching JQuery - Hao Luo - php[tek] 2015 POST - A Closer Look 19 JQuery Fetch API $.ajax('/applications',  {      method:  'POST',      contentType:  'application/json',      processData:  false,      data:  JSON.stringify({              name:  'Joe  Bob',              reason:  'Too  cold  outside'      })   })   .then(function  success(application)  {      appendApplicationHTML(application);   })   .fail(function  failed()  {      console.log('request  failed!');   });   fetch('/users',  {      method:  'post',      headers:  {          'Content-­‐Type':  'application/json'      },      body:  JSON.stringify({          name:  'Joe  Bob',          reason:  'Too  Cold  Outside'      })   })   .then(function  (response)  {      return  response.json();   })   .then(function  (application)  {      appendApplicationHTML(application);   })   .catch(function(error)  {      console.log('request  failed',  error);   });  
  • 20. Ditching JQuery - Hao Luo - php[tek] 2015 Eliminates Callback hell Offers More Flexibility and Freedom Promises are awesome 20
  • 21. Ditching JQuery - Hao Luo - php[tek] 2015 Utilities 21
  • 22. Ditching JQuery - Hao Luo - php[tek] 2015 DOM Loaded 22 JQuery Vanilla JS $(function(event)  {      console.log("DOM  fully  loaded  and  parsed");   });   document.addEventListener("DOMContentLoaded",   function(event)  {          console.log("DOM  fully  loaded  and  parsed");      });   yes yes yes 9+ Don’t use "load"
  • 23. Ditching JQuery - Hao Luo - php[tek] 2015 HTML Parse 23 JQuery Vanilla JS var  el  =  $.parseHTML(HTMLString); var  parser  =  new  DOMParser();     var  doc  =  parser.parseFromString(HTMLString,  'text/html');     var  el  =  doc.body.firstChild;   30 12 7.1 10+ function  parseHTML  (str)  {      var  tmp  =  document.implementation.createHTMLDocument('');      tmp.body.innerHTML  =  str;      return  tmp.body.firstChild;   };   IE9 won’t accept empty param yes yes yes 9+
  • 24. Ditching JQuery - Hao Luo - php[tek] 2015 Date Parse IE9 needs W3C output (which is also ISO 8601 compliant) (http://www.w3.org/TR/NOTE- datetime-970915.html) 24 <?php   $objDateTime  =  new  DateTime('NOW');   echo  $objDateTime-­‐>format('c');                              //  1975-­‐12-­‐25T14:15:16-­‐05:00  Yes  IE9   echo  $objDateTime-­‐>format(DateTime::ISO8601);  //  1975-­‐12-­‐25T14:15:16-­‐0500    No  IE9  
  • 25. Ditching JQuery - Hao Luo - php[tek] 2015 A word about JQuery Animate •Use Semantic HTML •Use CSS Transition 25 .application  {          opacity:  1;          max-­‐height:  300px;          transition:  max-­‐height  0.5s,  opacity  0.7s;   }   .application.removed  {          max-­‐height:  0;          opacity:  0;   }   CSS
  • 26. Ditching JQuery - Hao Luo - php[tek] 2015 Closing Thoughts 26
  • 27. Ditching JQuery - Hao Luo - php[tek] 201527 Non-Technical Reasons • a lot of magic is confusing sometimes • Understanding the basics makes you a better developer $('div');  //creates  a  jquery  instance  with  the  selection  inside   $('<div>');  //creates  a  jquery  instance  with  a  new  element  not  in  document   $($aJQueryInstance);  //makes  a  clone  of  $aJQueryInstance   $(function()  {})  //registers  function  to  run  after  DOM  is  loaded   $({foo:  'bar'});  //???  creates  a  jquery  set  that  has  a  subset  of  methods  ???   var  $appsEl1  =  $('#applications');   var  $appsEl2  =  $('#applications');   $appsEl1  ===  $appsEl2;  //false   var  appsEl1  =  document.querySelector('#applications');   var  appsEl2  =  document.querySelector('#applications');   appsEl1  ===  appsEl2;  //true  
  • 28. Ditching JQuery - Hao Luo - php[tek] 2015 Some Takeaways •Use Packages and Polyfills vs monolithic libraries & frameworks •Out of the JQuery Plugin Ecosystem and into NPM or Bower •Browser and Server 28
  • 29. Ditching JQuery - Hao Luo - php[tek] 2015 When to use JQuery •When you have to support IE8 •When you don’t have CORS •Abstractions sometimes are good! 29 uses requestAnimationFrames  for  its  animationsuses setInterval  for  its  animations
  • 30. Ditching JQuery - Hao Luo - php[tek] 2015 Resources for DOM references http://blog.garstasio.com/you-dont-need-jquery/ http://youmightnotneedjquery.com/ http://html5please.com/ 30
  • 31. Ditching JQuery - Hao Luo - php[tek] 2015 Thank you! @howlowck https://joind.in/13726 31