AJAX - The Complete Reference

(avery) #1

5


Developing an Ajax Library


I


n the previous chapters, we presented the basic ideas of JavaScript communications,
XHRs, and the data that is passed with these techniques. In this chapter, we begin our
focus on applying these ideas to implement real Web applications. To improve reuse,
we’ll aim to build a simple library to perform Ajax-style communications reliably. We
acknowledge the existence of libraries to perform such tasks, but the effort in developing this
communication library is primarily as an educational tool. It will be used to demonstrate more
complex ideas, build examples, and illustrate many of the decisions that must be made when
employing Ajax. Some of the more popular open-source Ajax libraries will be introduced at
the conclusion of the chapter to point readers to where they may end up later, but given the
volatility of syntax and support of these offerings, the book library will be used wherever
reasonable in future chapters.

Not Another Ajax Library!


At the time of this edition, there are literally 200+ Ajax-related libraries and toolkits to choose
from. Be prepared to be shocked if you have the time to evaluate some of these offerings:
you’ll find that a number of the ideas presented in previous chapters are not handled and
quite a number in the following chapters are certainly not. Given that this is a book about
Ajax, the primary goal when looking at a JavaScript library is to see how well it supports
core communications. Most of the libraries out there will wrap the XMLHttpRequest object,
but not all of them provide even the basic network management that will be put into this
library. Advanced libraries will certainly address this and potentially add many other
features. However, when building an Ajax application there are more issues beyond
communication to consider. For example, does the library provide useful features to
manipulate the DOM? Does it provide features to manipulate XML? How about event
management? Beyond lower level features, does it provide UI widgets? If some of these
features are not provided, how easily can it be extended to do so? Table 5-1 describes some of
the feature criteria that may be considered when evaluating a client-side Ajax framework.
Beyond the features presented in Table 5-1, some basic characteristics of the library must
be considered. Is the library easy to use? In other words, would it be easier to write more code
by hand than to use a misbehaving or complex library call? Is the library well documented so
it can be learned easily? Interestingly, many of the libraries online are not. Is the library fast or
does it add bloat and overhead to your JavaScript? Is the library good at what it does or does

177


CHAPTER


http://www.ebooks.org.in

Free download pdf