Top Banner
JavaScript Libraries Ajax Experience - July 2007 John Resig (ejohn.org)
62

JavaScript Library Overview (Ajax Exp West 2007)

Aug 20, 2015

Download

Documents

jeresig
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: JavaScript Library Overview (Ajax Exp West 2007)

JavaScript LibrariesAjax Experience - July 2007

John Resig (ejohn.org)

Page 2: JavaScript Library Overview (Ajax Exp West 2007)

Question: How do you want to write JavaScript?

Page 3: JavaScript Library Overview (Ajax Exp West 2007)

1) Plug-and-Play

• Drop in a “calendar widget” or “tabbed navigation”

• Little, to no, JavaScript experience required.

• Just customize some options and go.

• No flexibility.

Page 4: JavaScript Library Overview (Ajax Exp West 2007)

2) Some Assembly Required

• Write common utilities

• Click a link, load a page via Ajax

• Build a dynamic menu

• Creating interactive forms

• Use pre-made code to distance yourself from browser bugs.

• Flexible, until you hit a browser bug.

Page 5: JavaScript Library Overview (Ajax Exp West 2007)

3) Down-and-Dirty

• Write all JavaScript code from scratch

• Deal, directly, with browser bugs

• Quirksmode is your lifeline

• Excessively flexible, to the point of hinderance.

Page 6: JavaScript Library Overview (Ajax Exp West 2007)

What we’ve just seen...

• Widgets

• Libraries

• Raw JavaScript

Page 7: JavaScript Library Overview (Ajax Exp West 2007)

What we’ve just seen...

• Widgets

• Libraries

• Raw JavaScript

Page 8: JavaScript Library Overview (Ajax Exp West 2007)

Why use a library?

• Makes JavaScript bearable

• Gets the job done fast

• Simplifies cross-browser support

• Sort of like C stdlib - no one just codes C by hand

Page 9: JavaScript Library Overview (Ajax Exp West 2007)

What kind of libraries exist?Open Source Commercial

Client/ Server

AjaxCFCQcodo

AtlasBackbase for

Struts

Browser Only

PrototypeDojo

jQueryMootoolsYahoo UI

BackbaseSmartClient

Page 10: JavaScript Library Overview (Ajax Exp West 2007)

What kind of libraries exist?Open Source Commercial

Client/ Server

AjaxCFCQcodo

AtlasBackbase for

Struts

Browser Only

PrototypeDojo

jQueryMootoolsYahoo UI

BackbaseSmartClient

Page 11: JavaScript Library Overview (Ajax Exp West 2007)

Open Source LibrariesBrowser Only Client/Server

Task Specific

Scriptaculousmoo.fx

Open Rico

AjaxCFCQcodo

General Purpose

PrototypeDojo

jQueryMootoolsYahoo UI

Ruby on RailsCakePHP

Page 12: JavaScript Library Overview (Ajax Exp West 2007)

Open Source LibrariesBrowser Only Client/Server

Task Specific

Scriptaculousmoo.fx

Open Rico

AjaxCFCQcodo

General Purpose

PrototypeDojo

jQueryMootoolsYahoo UI

Ruby on RailsCakePHP

Page 13: JavaScript Library Overview (Ajax Exp West 2007)

What should a library have?

• DOM Traversing/Manipulation

• Event binding

• Ajax Support

• Basic Animations

Page 14: JavaScript Library Overview (Ajax Exp West 2007)

What should a library have?

• Some want complex controls

• Drag-and-drop

• Auto-complete search

• Others want language enhancements

• Object.extend()

• Array.each()

• DOM, Event, Effects, Ajax is a good middle-ground

Page 15: JavaScript Library Overview (Ajax Exp West 2007)

Secondary Features

• Documentation

• Community Support

• File Size

• Popularity

Page 16: JavaScript Library Overview (Ajax Exp West 2007)

Secondary Features

• Documentation

• Community Support

• File Size

• Popularity

(Practical)

(Esoteric)

Page 17: JavaScript Library Overview (Ajax Exp West 2007)

The Libraries

Page 18: JavaScript Library Overview (Ajax Exp West 2007)

Dojo

Page 19: JavaScript Library Overview (Ajax Exp West 2007)

Dojo: Overview

• Started early 2005 by Alex Russell

• Large development community

• Lots of corporate backing (IBM, AOL)

• Big code base, tons of features

Page 20: JavaScript Library Overview (Ajax Exp West 2007)

Dojo: Focus

• Building complete web applications

• A package heirarchy, e.g.:dojo.addClass( ... )

• Focus has transcended into widgets (Dijit)

• Huge number of features

• Today we’re looking at Dojo 0.9

Page 21: JavaScript Library Overview (Ajax Exp West 2007)

Dojo: DOM Support

• Good DOM Modification support - handles many cross-browser issues

• Great DOM Traversal with Selectorsdojo.forEach( dojo.query(“table tr:nth-child(even)”), function(row){ dojo.addClass( row, "odd" );});

Page 22: JavaScript Library Overview (Ajax Exp West 2007)

Dojo: Events and Effects

• Events support is complete and cross browser

• Good selection of generic animations

dojo.connect(dojo.byId("mylink"), "click", function(){ dojo.fadeOut({ node: this, duration: 500 });});

Page 23: JavaScript Library Overview (Ajax Exp West 2007)

Dojo: Ajax

• Supports a wide variety of Ajax communication

• Cross-domain Ajax support

• Built-in back button support

Page 24: JavaScript Library Overview (Ajax Exp West 2007)

Dojo: Docs & Community

• Documentation: Rough.In the middle of a major documentation overhaul for 0.9.

• Community: LivelyActive forum with frequent discussions.

Page 25: JavaScript Library Overview (Ajax Exp West 2007)

Dojo: File Size & Popularity

• File Size: Large (100Kb compressed)It’s highly recommended that you remove unused modules.

• Popularity: SubstantialBacking from many corporate sponsors (IBM).

Page 26: JavaScript Library Overview (Ajax Exp West 2007)

Prototype

Page 27: JavaScript Library Overview (Ajax Exp West 2007)

Prototype: Overview

• Started early 2005 by Sam Stephenson

• Incredibly popular, tied with Ruby on Rails’ popularity

• Development backed by 37 Signals

Page 28: JavaScript Library Overview (Ajax Exp West 2007)

Prototype: Focus

• Improving the usability of the JavaScript language

• Big emphasis on adding in ‘missing’ JavaScript features

• Clean structure, clean objects and ‘classes’

Page 29: JavaScript Library Overview (Ajax Exp West 2007)

Prototype: DOM Support

• DOM Modification works quite well:Insertion.Bottom(“list”,”<li>Another item</li>”);

• So does DOM Traversing:$$(“table > tr”).invoke(“addClassName”,”row”);

Page 30: JavaScript Library Overview (Ajax Exp West 2007)

Prototype: Events & Ajax

• Event binding just works:Event.observe(“button”,”click”, function(){ alert(“Thanks for the click!”);});

• So does Ajax:new Ajax.Request(“test.html”, { method: “GET”, onComplete: function(res){ alert( res.responseText ); }});

Page 31: JavaScript Library Overview (Ajax Exp West 2007)

Prototype: Details

• Code quality is fantastic, great features

• No included support for animations

• moo.fx

• Script.aculo.us

• Updated frequently

Page 32: JavaScript Library Overview (Ajax Exp West 2007)

Prototype: Docs & Community

• Documentation: GoodOfficial API documentation, some tutorials

• Community: DistributedMany bloggers love Prototype, little centralized discussion (23 posts/day).

Page 33: JavaScript Library Overview (Ajax Exp West 2007)

Prototype: File Size & Popularity

• File Size: Moderate (99KB)Unfortunately, not easily compressible with Packer - they recommend GZIP.

• Popularity: StrongApple, NBC, ESPN, CNN, Amazon

Page 34: JavaScript Library Overview (Ajax Exp West 2007)

jQuery

Page 35: JavaScript Library Overview (Ajax Exp West 2007)

jQuery: Overview

• Released January 2006 by John Resig

• Rapid rise in popularity

• Many developers across the globe

Page 36: JavaScript Library Overview (Ajax Exp West 2007)

jQuery: Focus

• Improving the interaction between JavaScript and HTML

• Finding elements then performing actions

• Highly-effective, short, code

Page 37: JavaScript Library Overview (Ajax Exp West 2007)

jQuery: DOM Support

• DOM Traversing is great - CSS1-3 support and basic XPath:$(“div > p:nth-child(odd)”)

• DOM Manipulation too:$(“#li”).append(“<li>An item</li>”);

Page 38: JavaScript Library Overview (Ajax Exp West 2007)

jQuery: Events, Effects, and Ajax

• Events are fully functional:$(“div”).click( showItem );

• And effects:$(“#menu”).slideDown(“slow”);

• And Ajax!$(“form”).submit(function(){ $(“#results”).load(“test.html”);});

Page 39: JavaScript Library Overview (Ajax Exp West 2007)

jQuery: Details

• Core features are limited to DOM, Events, Effects, Ajax

• Other features can be added in via plugins

Page 40: JavaScript Library Overview (Ajax Exp West 2007)

jQuery: Docs & Community

• Documentation: CompleteFully documented, complete API.

• Community: Vibrant108+ Mailing List Posts/Day

Page 41: JavaScript Library Overview (Ajax Exp West 2007)

jQuery: File Size & Popularity

• File Size: SmallAbout 20KB with everything.

• Popularity: StrongUsers: IBM, Technorati, MSNBC, DiggProjects: Drupal, Wordpress

Page 42: JavaScript Library Overview (Ajax Exp West 2007)

Mootools

Page 43: JavaScript Library Overview (Ajax Exp West 2007)

Mootools: Overview

• Released Sept 2006 by Valerio Proietti

• Created as a fork of Prototype, Base, and moo.fx

Page 44: JavaScript Library Overview (Ajax Exp West 2007)

Mootools: Focus

• Designed to fulfill common activities (All the way from low-level iteration to high-level Drag-and-Drop)

• Classical structure (like Prototype)

Page 45: JavaScript Library Overview (Ajax Exp West 2007)

Mootools: DOM Support

• Good DOM Selector support:$$(“body”)

• Plenty of helper functions for DOM modification:$(‘test’).appendText(“foo”);$(‘test’).removeClass(“foo”);

Page 46: JavaScript Library Overview (Ajax Exp West 2007)

Mootools: Events and Effects

• Has traditional event model:$(‘test’).addEvent(‘keydown’, function(){..});

• Plenty of visual effects too:var marginChange = new Fx.Style('myElement', 'margin-top',{duration:500});marginChange.start(10, 100);

Page 47: JavaScript Library Overview (Ajax Exp West 2007)

Mootools: Ajax

• Ajax support is fully functional:var myAjax = new Ajax(url, {method: 'get'}).request();

Page 48: JavaScript Library Overview (Ajax Exp West 2007)

Mootools: Details

• Lots of plug-and-play features

• Drag-and-Drop

• Accordion

• Scrollbar

Page 49: JavaScript Library Overview (Ajax Exp West 2007)

Mootools: Docs & Community

• Documentation: GoodGood API coverage, some tutorials

• Community: ModerateActive forum, hostile against “newbies”

Page 50: JavaScript Library Overview (Ajax Exp West 2007)

Mootools: File Size & Popularity

• File Size: Small (approx. 25KB, compressed)Has a full compilation system, you can pick-and-choose components.

• Popularity: RisingUbuntu, C|Net

Page 51: JavaScript Library Overview (Ajax Exp West 2007)

Yahoo! UI

Page 52: JavaScript Library Overview (Ajax Exp West 2007)

YUI: Overview

• Released Feb 2006 by Yahoo!

• Maintained and financed internally

• Attempt to standardize internal JavaScript

Page 53: JavaScript Library Overview (Ajax Exp West 2007)

YUI: Focus

• Exposing, and solving, common methodologies

• Looking for common idioms (Drag-and-Drop, Calendar, Auto-Complete)

Page 54: JavaScript Library Overview (Ajax Exp West 2007)

YUI: DOM Support

• DOM Traversal is minimal, no selectors:YAHOO.util.Dom.get(“list”)

• DOM Modification is also minimal, modification only (no DOM creation):YAHOO.util.Dom.addClass(“list”,”hover”)

Page 55: JavaScript Library Overview (Ajax Exp West 2007)

YUI: Events and Effects

• Full Event support:YAHOO.util.Event.addEventListener( “list”, “click”, function(){ alert(“List Clicked”); });

• Animations are also customizable:new YAHOO.util.Anim(“list”, { width: { from: 10, to: 100 } }, 1, YAHOO.util.Easing.easeOut);

Page 56: JavaScript Library Overview (Ajax Exp West 2007)

YUI: Ajax

• Ajax connections are simple to setup: YAHOO.util.Connect.asyncRequest( 'GET', “test.html”, function(){ alert(“File loaded”); }, null);

Page 57: JavaScript Library Overview (Ajax Exp West 2007)

YUI: Details

• Namespaces can become quite verbose. It is recommended that you copy namespaces to other variables.var dom = YAHOO.util.Dom;

• Closed development (Yahoo employees only, no subversion repository)

Page 58: JavaScript Library Overview (Ajax Exp West 2007)

YUI: Docs & Community

• Documentation: ExcellentEverything is thoroughly documented. Lots of explanations, plenty of demos.

• Community: ModerateMailing List hovering around 36 posts/day.

Page 59: JavaScript Library Overview (Ajax Exp West 2007)

YUI: File Size & Popularity

• File Size: 40KB (Compressed)Code is quite modular, you can remove un-used code easily.

• Popularity: Possibly WaningMany good bloggers use to talk about it - have moved on.

Page 60: JavaScript Library Overview (Ajax Exp West 2007)

Feature Summary

DOM Events Effects Ajax

Dojo X X X X

Prototype X X - X

jQuery X X X X

Mootools X X X X

Yahoo UI / X X X

Page 61: JavaScript Library Overview (Ajax Exp West 2007)

More Information

• Dojo: http://dojotoolkit.org/

• Prototype: http://prototypejs.org/

• jQuery: http://jquery.com/

• Mootools: http://mootools.net/

• Yahoo! UI: http://developer.yahoo.com/yui/

Page 62: JavaScript Library Overview (Ajax Exp West 2007)

Ajax Experience Presentations

• Presentations on:

• Dojo (3)

• Prototype (3) & Scriptaculous (1)

• jQuery (3)

• Go to one that sounds interesting and enjoy!