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

Code: Hello world optimized step 3

Chapter 8 - Ajax Optimization

Finally, if we apply an optimization to the ID values that represent the touch points between the markup and script, renaming the button from button1 to b and the output div ID to simply o, we can chop a few more bytes off and reach an even smaller size of 1,001 bytes (making it more than 33% smaller):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/
xhtml1/DTD/xhtml1-transitional.dtd"<<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Ajax
Hello World</title><script type="text/javascript">d=document;M="Msxml2.
XMLHTTP";function c( ){try{return new XMLHttpRequest(
)}catch(e){}try{A=ActiveXObject;return new A(M+".6.0")}catch(e){}try {return new
A(M+".3.0")}catch(e){}try {return new A(M)}catch(e){}try {return new A("Microsoft.
XMLHTTP")}catch(e){}}function s( ){var x=c( );if(x){x.open("GET","sayhello.php");x.
onreadystatechange=function( ){if(x.readyState==4&&x.status==200)d.
getElementById("o").innerHTML=x.responseXML.getElementsByTagName("message")[0].
firstChild.nodeValue};x.send( );}}window.onload=function( ){d.getElementById("b").
onclick=s}</script></head><body><form action="#"><input type="button" value="Say it!"
id="b" /></form><br /><br /><div id="o"> </div></body></html>
Copyright © 2002-2017 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