Friday, May 12th, 2006

Ajax Experience Day 2: Alex Russell’s Dojo In Depth

Category: The Ajax Experience

Notes from Alex Russell’s “Dojo In Depth” talk at The Ajax Experience, continuing on from his Intro To Dojo and covering more advanced topics.

Other Talks at the Ajax Experience

Dylan on Events, Brad on Storage

Javascript

“Javascript is not a bug that needs fixing.” Dojo builds tools that help you get things done with this great language.

Q: What’s AOL’s role in Dojo? (Alex mentioned AOL has contributed code.)
A: Dojo is run by a non-profit organisation. AOL is using Dojo, e.g. ?APages, so have a stake in making it good, feeding back, etc.

Animation

dojo.lfx.propertyAnimation. With a single call: “I want to animate those two nodes, over half a second. Move their height from x to y and their opacity from a to b”.

Easing.lfx.easeIn, easeOut, easeInOut:

Chaining (touched on in previous session).

Q: Can say “go to half size, certain percent, etc.”
A: Not yet.

Q: Can do animation loop?
A: Yes, it’s a new feature.

Build System

It’s OPTIONAL. If you pick up a standard build off the distro site, you’ll never need to see it.

Optimisation Strategies

What matters most is perceived speed, not actual. Ajax is in some respects
slower, but feels faster.

  • Cache. Pragmas etc.
  • Fewer requests Can talk to 2 domains at once using HTTP 1.1 + ?
  • No synchronous/blocking requests
  • Reduce size “on the wire” (gzip)

Build

Q:What is a shim?
A: Use it to make buildings level. Little pieces of wood to make it level. Virtual equivalent is things to make it portable, regardless of details. (MM – “an equaliser”).

Q: How to get tests running?
A: There’s a test dir. Anything with test_* will be run. Inside it, each
function is called test_…().

In this demo, runs under spidermonkey. Could also run against rhino.

Was previously using JSUnit and had wrapper for them. Now the wrapper has evolved to its own implementation, not using those anymore.

Dojo is pure JS. Has host environments (?Rhino etc)

Where Widgets Come From

Web development isn’t best-case situation. Ideally we’d be using Cocoa etc etc, but we have to make the best of what we have.

Should be just as simple to declare for SVG etc as HTML. Widget system not HTML-specific. When declare a widget the first time, Dojo searches through namespace to find the most specific widget available for this environment. dojo.widget.html.FooWidget, then searches dojo.widget.FooWidget, dojo.widget.HTMLWidget, dojo.widget.DOMWidget, dojo.widget.Widget. (That’s the inheritance hierarchy).

Widget Construction. There’s a standard call sequence: create(). satisfyPropertySets() … initialize() etc. These are implemented by each widget.

Based on templates.

Q: How are templates loaded?
A: In sequence.

How many widgets can you realistically have?
A: Spent a lot of time optimising widget system. Per-widget rendering time is
about 10 milliseconds. That figure tends to scale up linearly except on IE. ie
100 widgegts in about a second. Look at e.g. renkoo for real-world usage of
widgets.

Fastest way is often to build an entire page as the widget. ie html, head,
body, the whole thing. CSS referenced from the head in the usual HTML way.
dojoattachpoint is actually embedded in a node somewhere within the body. (It
doesn’t have to be the root of the whole thing.)

Cross-Domain IO

Standard Ajax XHR calls are pretty secure, can’t do anything couldn’t already do. But Cross-Domain is more dangerous.

dojo.io.ScriptSrcIO makes JSON calls, supports JSONP.

Yahoo’s been great about exposing services as JS, but all on different services, wanted unified interface: dojo.rpc.YahooService

Q: What is “defer”?
A: Continuation passing style for languages that don’t support it, based on Twisted Python concepts and borrowed from Mochikit.

Now have Cross-Domain Dojo. Asynchronous (was previously loading packages synchronously). Can load all from one site. More work to configure.

Q: How does this Cross-Domain stuff work?
A: By adding a Script tag dynamically. Took a while for Safari to implement, but can now do it.

Q: How does this handle different Dojo versions?
A: Working on it.

Performance

Fire up Renkoo, view source. Only around 50 lines because using all based on Dojo widgets.

Load modules only when needed.

Posted by Michael Mahemoff at 10:48 am
Comment here

+++--
3.6 rating from 16 votes

Comments Here »

Comments feed TrackBack URI

Leave a comment

You must be logged in to post a comment.