AJAX - The Complete Reference

(avery) #1

262 Part II: Developing an Ajax Library^


You should be able to modify a Web application or the server itself to return compressed
content for some requests and standard content for others. For example, using PHP, it is
possible to look at the request headers and then start compression, as shown here:

if (isset($headers["Accept-Encoding"]))
{
ob_start();
ob_implicit_flush(0);
}

If the header was not set, the content is sent as normal without the compression handler in
play. For textual data, this encoded data can make quite a difference. As seen in Figure 6-18,
there may be a nearly 80 percent reduction in size between the compressed and uncompressed.
Note that this is only on the textual content, and it works just fine with an XHR. As a
demonstration of this, the example at http://ajaxref.com/ch6/compress.html allows you to

FIGURE 6-18 Compressed versus uncompressed responses compared
Free download pdf