Datasheet
and the images and multimedia documents referenced in the body section. This behavior explains the
burst of exchanges logged by the server from the second line to the line preceding the last line. These
exchanges follow the same pattern that was used to download the initial XHTML document.
The scripts are executed as soon as they are loaded by the browser. However, most of the actions that are
performed by these scripts require that the page and all its scripts and CSS have been loaded. Executing
action before that stage would mean that they cannot be sure that the other scripts on which they rely
have already been loaded, and also that they don’t know if the HTML document itself is complete. A
common pattern is thus to perform declarations in each script and trigger their initialization and the
beginning of the real work with a
load event that is sent by the browser when everything has been
loaded. A typical example of this pattern is
script.js, the BuzzWatch main script:
YAHOO.namespace(“buzzWatch”);
YAHOO.namespace(“editInPlace”);
function init() {
initMenuBar();
initConfig();
initPanels();
initEditInPlace();
initController();
}
.
.
.
YAHOO.util.Event.addListener(window, “load”, init);
The first two lines are YUI-specific initializations. The next lines define an init function that performs
the initialization of the BuzzWatch application, and the last one uses the YUI event utility to require that
the
init function is called when the page is loaded. If you freeze your browser after the page has been
loaded and before the load event has been propagated to the different function that performs the initial-
ization of the application, you’ll see a page (Figure 1-3) that looks very different from what you see after
the initialization, and the difference between these two views is the domain of Ajax programming.
If you want to reproduce this figure, there are a couple of ways to freeze your browser after loading and
before initialization. The first is simply to disable JavaScript before you load the page. The second is to
use a JavaScript debugger available for your browser and add a breakpoint at the beginning of the
init
function.
You wouldn’t expect to be walked through the 700 lines of JavaScript that power BuzzWatch in this first
chapter, but you’re probably curious to see what type of tasks are performed in Web 2.0 applications.
To categorize these tasks, you can consider that they fall into three main categories:
❑ Changing the document that is displayed
❑ Reacting to user interaction
❑ Interacting with web servers
9
Hello Web 2.0 World
04_087889 ch01.qxp 5/2/07 12:56 PM Page 9