Code: Hello world optimized step 1

Chapter 8 - Ajax Optimization

If we crunch down the script portion of the page, as shown next, we reduce the overall file size to 1,043 bytes, which is more than a 30% savings:

<!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("output").innerHTML=x.responseXML.
getElementsByTagName("message")[0].firstChild.nodeValue};x.send( );}}
window.onload=function( ){d.getElementById("button1").onclick=s}
</script>
</head>
<body>
<form action="#">
<input type="button" value="Say it!" id="button1" />
</form>
<br /><br />
<div id="output"> </div>
</body>
</html>