AJAX - The Complete Reference

(avery) #1

276 Part II: Developing an Ajax Library^


Prefetching can improve performance dramatically, but it does so at the expense of
bandwidth (see Figure 6-22) as there is always that chance that the user will never use the
content that is prefetched.
Ajax can also be used to perform prefetching. For example, if you had a paginated table
of data, you might consider fetching the next set of requests ahead of time, so that when the
user pages forward it is already there. An example of this is displayed in Figure 6-23
(http://ajaxref.com/ch6/customprefetch.html), which shows that the next set of requests
was requested while the current values were pulled from a prepopulated custom Ajax cache
introduced a few pages back.
Of course, exactly how much you fetch ahead of time is a fine balance between UI
smoothness and bandwidth consumption. We explore this very idea in Chapter 8, where we
put this technique to good use in a variety of ways.

Get the Balance Right


For fast Ajax applications, the first rule is quite plain and simple: watch what you send and
how you send it. Forget compression or even caching if you simply don’t need to send
something. Why send a packet in XML if there is no need to do so? Why send data in a
response if it isn’t necessary? For example, if a user deletes an item from a list, why return

FIGURE 6-22 Big savings via browser-native prefetching
Free download pdf