Call (877) SITE-OPT (748-3678)

Code: YUI Ajax library version of Hello World

Chapter 8 - Ajax Optimization

Finally, the YUI version is shown next. It is probably the most straightforward of the bunch coding-wise, but the inclusion of multiple script files requires more HTTP requests. To be fair, however, Yahoo! provides a special minified, gzipped, and cached version of its library online in case you want to take advantage of all of its optimization work. Yahoo! will also serve the files from its server closest to the user for optimal response time. The minified and gzipped version of Yahoo!'s Ajax library is 73.2% smaller than the unoptimized version.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>YUI Hello Ajax World</title>
<script src="" type="text/
<script src="" type="text/
<script src=""
<script type="text/javascript">

function sendRequest( )
    YAHOO.util.Connect.asyncRequest('GET', "sayhello.php", { success:responseCallback }, null);

function responseCallback(response)
    var msg = response.responseXML.getElementsByTagName("message")[0].firstChild.nodeValue;
    document.getElementById("responseOutput").innerHTML = msg;

YAHOO.util.Event.addListener('button1','click', sendRequest );

<form action="#">
    <input type="button" value="Say it!" id="button1" />

<br /><br />
<div id="output"> </div>

Copyright © 2002-2018 Website Optimization, LLC. All Rights Reserved - Free website speed test - Privacy Policy
Last modified: February 19, 2009.

Follow us on: Twitter, Google+, Facebook, Linked In