AJAX - The Complete Reference

(avery) #1

6 Networking Considerations


W


eb delivery is fraught with risk. Servers go down, data can be lost, and connections
can crawl. Ajax developers who do not respect the inherent challenges of network
delivery on the public Internet are at best naïve and at worst plain foolish.
Unfortunately, blissful ignorance of exactly how many pages do make it to a user complete
and on time is the norm, not the exception, in Web development at this point in history. While
users may complain in the case of major failures, more often than not, the masses silently and
dutifully hit reload and back to rectify the occasional error encountered between page loads.
Ajax applications that communicate all the time simply provide no predictability to users as to
when errors may occur, destroying the inherent “layer 8” error correction Web developers
have enjoyed for years. In such an environment, the occasionally failing site and application is
now considered fragile or annoying. It is our job as Ajax developers to understand and
optimize network communications, expect transmission and server failures, mitigate such
failures if possible, and inform users if not. In support of this worthy goal, in this chapter we
expose a number of challenges in Ajax-based communications and solve them in light of the
educational wrapper library from the previous chapter.

What Could Go Wrong?


As Web developers, we rely on high quality, fast and robust network communications. Like it
or not, such an assumption is quite dangerous, particularly if the communication takes place
over the Internet at large as opposed to a robust local LAN. All the things that can go wrong
during requests should be carefully considered and addressed if at all possible. In the case of
a basic request-response cycle, as seen in all network applications including those that are
Ajax based, the problems that might be encountered can be roughly broken out like so:


  • A request never returns.

  • A request returns, but too slowly.

  • A request returns and is in error.


If a request returns in error, there are many possible causes. It could be that the client
induced the error by not asking for the correct resource or calling the resource with the
wrong parameters. However, it also might be that the server hit an error condition such as a
permission problem, load issue, or a multitude of other possibilities. You might even

231


CHAPTER


http://www.ebooks.org.in

Free download pdf