4.2. Integrating AJAX into a Framework
Whether you're planning to add only a few simple AJAX features or use AJAX throughout your site, integrating it into your current Web site design is a must. The more formal the framework, the harder the process isespecially if your framework provides a front controller that is heavily optimized for generating HTML. Frameworks without a front controller have an easier time incorporating AJAX because they can add a new entry point just for AJAX; many AJAX Remote Procedure Call (RPC) implementations provide code to help do this.
The way you integrate with a front controller depends heavily on the style of AJAX you're performing. If you're taking a document-centric approach, integration is generally easy; you just need the ability to create pages in the needed output format. (The controller's normal name spacing will work just fine.) This may take some new development, depending on your current design, because you'll need to generate small chunks of HTML (or other data formats, such as XML) instead of full pages. You will also need to make some naming decisions, such as whether you are going to put your AJAX pages next to normal pages or into their own distinct namespace. A distinct namespace makes it easy to locate your AJAX code, but it divides the code by usage instead of by function, so you can't see the AJAX code's relation to its non-AJAX version. Adding in AJAX pages next to your normal code lets you see the relation, but it makes it much harder to identify all of an application's AJAX-entry points. Either option can work well; the most important point is to use a consistent approach.