Preface

Users now demand web applications that look and feel like those of the desktop. Home computers have long since become ubiquitous, web browsers are the enabling platform, and virtually everyone on the planet is a potential end user. Software developers are spending more time than ever getting their applications into the browser for a potential audience of millions—many of them trying to grab a handful of the multibillion dollar advertising wave, while others are capitalizing on the sheer elegance and convenience of an application that is impressive enough that people will be willing to pay for access to it.

Of course, just because the web browser is the enabling platform does not mean that it is the ideal platform—at least not in its current manifestation. Corporate politics, less than uniform implementations of the various specifications for web browser technologies, and a curious evolution of protocols and standards over almost two decades have made deploying an application in the browser a lot more difficult than anyone might have ever predicted.

But in a world where necessity breeds imagination and innovation, there is always hope.

Fortunately, the rich and powerful functionality JavaScript provides makes it possible to manipulate, customize, and augment a web page on the fly, and in doing so, makes it possible to provide a layer of insulation between the developer and the bare metal of the web browsers—even all of them at the same time.

This book is about Dojo, a JavaScript toolkit that provides that layer of insulation between you and the hard knocks of browser inconsistencies by leveraging JavaScript and other web technologies for all that they're worth—not by attempting to build a brittle, superficial layer to reimplement or work around them. Dojo makes a great addition to a project that's already using YUI![1] or even a server side framework that might benefit from offloading some of the work over to the client.

Dojo packs the standard JavaScript library you've always wanted, the collection of drop-in replacements for the customized HTML controls and CSS layout hacks you've implemented again and again, and the build tools and unit tests that would have been so handy when it came time for migrating to production. Dojo isn't just a JavaScript toolkit, Dojo is the JavaScript toolkit—and right now is a great time to learn how to use it to make your life easier and the experience of your end users everything that it possibly can be. Dojo is revolutionizing web development, and gaining momentum fast.

Whatever web development project may be on your horizon, rest assured that Dojo can help you realize it quickly and with minimal boilerplate so that you're left with the cleanest, most maintainable implementation possible. My sincere hope is that this book relates Dojo's story so effectively that you'll spend minimal time scrambling around for answers and be able to fully concentrate on engaging the challenging (and far more interesting) problems that you've set out to solve.

Why Dojo?

Undoubtedly, there is a swatch of JavaScript toolkits available today, so you might already be wondering what Dojo provides that you can't get somewhere else. Keeping in mind that the very nature of a toolkit or library being built upon a completely interpreted language makes it theoretically possible for any other toolkit to do the very same things, it's not so much what can Dojo do that other can't do; rather, it's more about the effectiveness of getting work done along with the community, philosophy, and licensing aspects that surround it.

You might think of it like this: it's theoretically possible to build a house using only a hammer, a shovel, a saw, and a lot of nails—but at what expense? Clearly, some heavy machinery and some carpenters to support you along the way would be a tremendous boon. The situation with Dojo is quite similar. The following list attempts to highlight (in no particular order) some of the places where Dojo really shines and differentiates itself:

Community

Although it could be considered a nontechnical issue, Dojo's open community is one of its top strengths. The Dojo Foundation, a nonprofit organization set up for the purpose of providing a vendor-neutral guardian of intellectual property, backs the toolkit (and other interesting projects such as Cometd,[2] DWR,[3] and OpenRecord[4]), and is sponsored and supported by IBM, AOL, Sun, OpenLaszlo, Nexaweb, SitePen, BEA, Renkoo, and a slew of the greatest DHTML hackers in the world. If that doesn't tell you that it has good friends backing it, then what possibly could?

As a liberally licensed open source project with extremely low barriers to entry, your voice will be heard if you want it to be heard. If you pop into the IRC chat room #dojo on freenode.net and start talking, there's virtually no chance that you won't be heard by a committer or significant contributor to the project. Additionally, weekly IRC meetings are currently held on #dojo-meeting each Wednesday from 3 to 6 P.M. (PST), and you're more than welcome to pop in and eavesdrop or participate in the official meetings where both strategic and tactical issues are routinely discussed.

Knowing there's transparency in how Dojo is steered strategically and developed tactically is very compelling. As other JavaScript toolkits and libraries become increasingly commoditized, the Dojo community really stands out as different. The organizations and individuals who make up the team of committers (not to mention the thousands of individual developers out there building real web sites and applications) all give Dojo a particular character and grounding for success.

Liberal (and clean) licensing

Dojo is open source software that is liberally licensed under the terms of either the modified Berkeley Software Distribution (BSD) license or the Academic Free License (AFL) version 2.1. Except as noted in a few per-module license files, you get to choose the license you want to adopt for your specific work. All external contributions are required to be compatible with the BSD or AFL licenses, and all contributors must sign a Contributor License Agreement (CLA) that ensures the Dojo Foundation has clear title to all contributions—thereby protecting all users of the toolkit from intellectual licensing conundrums. The benefit of clean licensing is markedly not the case with several other popular JavaScript toolkits (that shall be left unnamed).

Depth and breadth

While some toolkits tackle specific pieces of a problem space, Dojo provides an end-to-end solution for development in the browser. Everything from standard library utilities to turnkey widgets to build tools and a testing framework—it's all in there, so you seldom have to look elsewhere. But don't let the breadth fool you into thinking that there is code bloat, because the build tools allow you to produce custom versions of the toolkit that can be as streamlined as your application permits.

While it is often the case that breadth hampers depth, it's not what happens with Dojo at all. Even inside of Base, the tiny kernel that provides the foundation for the rest of the toolkit, you have more functionality than you can shake a stick at—facilities for universally querying the DOM via CSS3 selectors, AJAX utilities, event normalization amongst various browsers—and then some. That doesn't even begin to touch of the rich library of application, form, and layout widgets, or the build tools.

Although the breadth and depth of Dojo produces a lot of complexity, the infrastructure is painstakingly reviewed on a continual basis by the some of the best web hackers in the world for high quality coding standards, consistent naming conventions, performance, maintainability, and overall ease of use for the application developer. Rest assured that you will be able to create a great user experience with Dojo.

Portability

While the JavaScript language is dynamic, powerful, and extremely expressive, there are still myriad issues that come up routinely that amount to fairly mundane engineering efforts. It's quite instructive to go through the motions that solve a central algorithmic problem or engineering conundrum, but at the end of the day, any code that you develop is code that you have to maintain, update, debug, and document.

As if those aren't enough good reasons, the motivation for having a JavaScript standard library may be especially compelling given the existing state of compatibility amongst browsers for various feature sets. While attempting to develop a feature that works uniformly across a set of modern browsers may not always be rocket science, it can be painfully tedious work that can demoralize even the most seasoned professionals.

The bottom line is that it's almost a certainty that as an application developer, you aren't going to be receiving any return on investment (or having very much fun) by jumping through all of those hoops. Instead, pick up production quality code that a community of other developers has developed, debugged, and tested—and then consider contributing back. Hopefully, that "giving back" part will come naturally enough once you've saved enough time and money by way of community-supported, open source software.

Pragmatic philosophy

Dojo embraces JavaScript for what it is instead of treating it like it's something that's broken and thereby trying to create a brittle, artificial layer on top of it that almost redefines it. While Dojo exposes tremendous functionality that protects you from the bare metal of the browser and does many things like normalize browser events behind the scenes so that you don't even have to think twice about them, it never attempts to reinvent JavaScript. For example, you won't find Dojo-specific functions for operations like deleting DOM nodes or walking the DOM tree because operations like childNodes, firstChild, lastChild, and removeChild work just fine across all browsers. However, whenever there are known inconsistencies, Dojo steps in to provide you with the tools you need to write portable code.

For that matter, Dojo doesn't attempt to lockout or constrain your use of other JavaScript libraries; it is not uncommon to see it used side-by-side with another technology like DWR or YUI!. And of course, as a client side technology, you are obviously free to use whatever technologies you'd like on the server since Dojo is server-agnostic.

A comprehensive survey of all of the popular JavaScript toolkits would reveal that they all have considerable overlap by virtue of being popular in the first place. So, when it comes time to make a decision about which toolkit or collection of toolkits is right for you, it is worth the time to really ponder the value of community, transparency, licensing, and the philosophy governing the technology in which you are about to invest time and possibly even money. Namely, you want to have support (community and documentation) when you need it, you don't want to invest in a project that's too brittle to be maintained or about to tank, and you want minimize your time working to plug holes that some other toolkit has already plugged.



[2] See http://www.cometd.com or http://www.cometdaily.com or a great coverage on Comet.

[3] See http://getahead.org/dwr for more on Direct Web Remoting.

[4] See http://www.openrecord.org for more on OpenRecord.

Get Dojo: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.