Archive for the ‘Tips’ Category

July 21st, 2009 Comments Off
Tags: , ,

Category: Articles, News, Tips

OSCON 2009 Materials Now Available

As promised this morning, I’ve made all of my materials for the 3 hour tutorial available under liberal licensing. All ~160 slides of them and accompanying code samples.

Also as promised, I removed the PHP dependencies for some of the server stuff and replaced it with a simple python server that uses cherrypy. You should hopefully have no problems getting the sample server to run. You should have no problems finding stuff on the net to help you get that setup if you have problems, but feel free to comment here as well. Additionally be sure to skim the README in there.

You can get the materials here.

Thanks again to everyone who attended. I hope that you were exposed to some of the great tools that Dojo can bring to the user experiences you are creating and that these slides are sufficiently succinct that they are a help to you. While they don’t cover everything in my book, they really do cover a lot of it…more than enough to get you pretty darn proficient.

Finally, remember that we’re having the tomorrow here in San Jose at 7pm. Please don’t miss it.

June 19th, 2009 Comments Off
Tags: , ,

Category: Articles, News, Tips, Vetted Links

Dojo Tips and Tricks

Many months ago, I wrote an article for InsideRIA that provided a topical look at some of the more useful things that Dojo provides you entitled Dojo Tips and Tricks. I’d actually forgotten that I even wrote the article so it was a surprise when a colleague wrote me earlier this morning and mentioned it.

It’s a bit more diverse than some drive-by-tutorials in that it digs into DojoX just a little bit and mentions the build system, so even if you’ve been using some of the core tools for a while now, you may still learn a few things from a quick read.

In between the time when the article was finished and now, Dojo has since updated to version 1.3 so you’ll unfortunately see a few CDN URLs that point to version 1.2; however, upgrading the URLs shouldn’t break anything. The latest and greatest is usually a great place to start, so I always encourage folks to stay up to date.

If you’re coming to OSCON this summer, be sure to drop by my 3 hour tutorial for a closer look at many of the great tools that Dojo provides.

February 18th, 2009 6 Comments »
Tags: ,

Category: Tips

Inspecting JSON APIs with afterOnLoad

On page 22 of my book, I provided a sidebar called “Injecting Dojo” in which I provided a hack for inserting Dojo into the page after onload (or equivalent) handlers have fired via dynamic SCRIPT tag insertion. The problem was that as of version 1.1, there wasn’t a good way to fire an addOnLoad handler after Dojo was ready, so the possibilities were a bit limited.

As of version 1.2, however, Dojo added full support for a configuration switch called afterOnLoad as well as the ability to pass in an addOnLoad handler right into djConfig. In combination, you get a nice, clean way to get Dojo running in the page after it’s already been loaded, whether it is via a bookmarklet or some other scenarios such as lazy-loading.

To demonstrate the utility of these features with a simple illustration, consider a scenario in which you’re debugging or inspecting a JSON API, and you’d like to reformat the output that appears in the browsers to be pretty-printed instead of all one one long line, so that it’s easier to read. You could install this snippet as a bookmarklet (by dragging and dropping that link into your browser’s toolbar for most browsers, or right clicking and saving it in IE) to get the job done:

(function() {
    afterOnLoad: true,
    addOnLoad: function() {
      var _json = dojo.fromJson(dojo.body().innerHTML);
      dojo.body().innerHTML= "<html><body><pre>"+
      dojo.toJson(_json, true /* pretty print*/)+
  var e=document.createElement("script");

As you can well infer, the script is simply taking the body of the page and rewriting it as nicely-formatted JSON. It’s not hard to imagine baking in a little regex that scrapes off the “padding” part of a JSON-P API if you needed that kind of support.