<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Seifi.org &#187; javascript</title>
	<atom:link href="http://www.seifi.org/category/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://www.seifi.org</link>
	<description>A Web Development Blog by Joe Seifi - seifi.org</description>
	<lastBuildDate>Thu, 12 Aug 2010 05:35:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Wishlist: Browsers contain major JavaScript libraries in memory</title>
		<link>http://www.seifi.org/javascript/wishlist-browsers-contain-major-javascript-libraries-in-memory.html</link>
		<comments>http://www.seifi.org/javascript/wishlist-browsers-contain-major-javascript-libraries-in-memory.html#comments</comments>
		<pubDate>Fri, 06 Mar 2009 08:18:01 +0000</pubDate>
		<dc:creator>Joe Seifi</dc:creator>
				<category><![CDATA[browsers]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.seifi.org/?p=726</guid>
		<description><![CDATA[Let&#8217;s face it, without JavaScript the web would be a boring place. Unless you roll your own, well you need to use a library of some sort, and in most cases you need more than just one library to achieve your intended user experience. Performance optimizations aside, and even if you concatenate all your JS [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s face it, without JavaScript the web would be a boring place. Unless you roll your own, well you need to use a library of some sort, and in most cases you need more than just one library to achieve your intended user experience.</p>
<p>Performance optimizations aside, and even if you concatenate all your JS files into a single file, you still have to load the library into the browser after the request has been made, and you can&#8217;t do anything with it until that has finished loading.</p>
<p>Wouldn&#8217;t it be so great if the browser had a copy of YUI or jQuery or Dojo or Prototype or GWT in memory at all times? Then your library using decision would not be influenced by the size of the library but by its speed and performance, and perhaps features and functionality provided. I mean you don&#8217;t go loading new fonts and new plugins every single time you go to a new page right? Then why do we have to download the same 5 or 6 JS libraries over and over all day long as we browse the web? And if this was an option how many companies would spend time rolling out their own rather than adopting one?</p>
<p>I understand there would be tons of politics involved and it will probably never happen in a million years but it is worth a try. Perhaps at least a FF only version could be done through an add-on that loads the latest major version of all these libraries and checks for updates on startup, similar to how other plugins get updated in FireFox today. The browser would have to namespace the libraries to avoid confusion. Developers would then just do a test to see if the browser has a required library in memory, and if not then make a server call for it as a fail safe. </p>
<p>It would take lots of collaboration and standardization. JavaScript was the sleeping giant that was brought to center stage with the success of frameworks and libraries that have fueled its standardization and resulting wider adoption. Why not give those libraries some credit and package them into your browsers?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seifi.org/javascript/wishlist-browsers-contain-major-javascript-libraries-in-memory.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Google Chrome First Impressions</title>
		<link>http://www.seifi.org/javascript/google-chrome-first-impressions.html</link>
		<comments>http://www.seifi.org/javascript/google-chrome-first-impressions.html#comments</comments>
		<pubDate>Tue, 02 Sep 2008 19:02:35 +0000</pubDate>
		<dc:creator>Joe Seifi</dc:creator>
				<category><![CDATA[browsers]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.seifi.org/?p=677</guid>
		<description><![CDATA[Yet another browser? Well here we go again. Let&#8217;s take a look at Chrome and see what it has to offer. The download page is located here. The installer for Windows XP is only 474KB! You can watch the press conference video about Google Chrome or read the Google Chrome Book in the meantime. What [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.seifi.org/wp-content/uploads/2008/09/googlechromelogo.jpg" alt="" title="Google Chrome Logo" width="55" height="53" class="alignnone size-full wp-image-683" hspace="15" align="right" />Yet another browser? Well here we go again. Let&#8217;s take a look at Chrome and see what it has to offer. The download page is <a href="http://www.google.com/chrome">located here</a>. The installer for Windows XP is only 474KB! You can watch the <a href="http://google.client.shareholder.com/Visitors/event/build2/MediaPresentation.cfm?MediaID=33101&#038;Player=1">press conference video</a> about Google Chrome or read the <a href="http://www.google.com/googlebooks/chrome/index.html">Google Chrome Book</a> in the meantime.</p>
<h3>What we knew so far about Chrome</h3>
<ul>
<li>Uses <a href="http://code.google.com/apis/v8/">V8 JavaScript engine</a> which supports Classes and compilation. There is a <a href="http://code.google.com/apis/v8/run.html">V8 JavaScript benchmark suite</a> that gives FireFox 3 a score of 83, while giving Chrome a score of 1213! Safari 3 gets a score of 128. Judging by this alone, V8 blows away the competition.</li>
<li>Uses Webkit rendering engine.</li>
<li>Tabs run as independent processes which can be managed.</li>
<li>Lots of other <a href="http://gears.google.com/chrome/intl/en/features.html">features</a>.</li>
</ul>
<h3>First Impressions</h3>
<ul>
<li>Installation was a breeze and imported FireFox settings.</li>
<li>No status bar, You only see the status bar when you hover over a hyperlink.</li>
<li>The Task Manager (Shift + Escape) updates in real time and shows memory, CPU and network usage for each tab, each plugin, and the main Chrome process separately. There is also a link to Stats for Nerds with lots more gritty info.</li>
<li>The Flash plugin is extremely CPU usage intensive and causes sluggishness when scrolling. I just loaded a popular <a href="http://www.adobe.com/products/acrobat/">flash website</a> and noticed my machine came down to a near halt. It seems to happen more with Flash files that contain infinite loops, using as much as 70% of the CPU.<br />
<img src="http://www.seifi.org/wp-content/uploads/2008/09/chrome_taskmanager_cpu.gif" alt="" title="Chrome Task Manager CPU Usage" width="377" height="164" class="alignnone size-full wp-image-681" />
</li>
<li>The built in JavaScript console looks like a combination of <a href="http://www.seifi.org/javascript/firebug_tips_and_tricks.html">FireBug</a> and <a href="http://www.seifi.org/css/whats-new-in-safari-31-web-inspector-and-sinppet-editor.html">Web Inspector</a>.</li>
<li>There is a built in JavaScript Debugger (Alt + `)</li>
<li>Passes the <a href="http://www.webstandards.org/files/acid2/test.html">Acid 2 test</a>.</li>
<li>Chrome gets a score of 78 on the <a href="http://acid3.acidtests.org/">Acid 3 test</a>, which is higher than FireFox 3 at 57, <a href="http://webkit.org/blog/158/the-acid-3-test/">Safari</a> at 72, and Opera at 45.<br />
<img src="http://www.seifi.org/wp-content/uploads/2008/09/chrome_acid3.gif" alt="" title="Chrome Acid 3 Results" width="450" height="369" class="alignnone size-full wp-image-682" />
</li>
<li>Omnibar &#8211; this is the URL/location bar in Chrome that has some fuzzy logic built in to suggest &#8220;smart&#8221; autocompletes. This is the current order of the drop down in the auto complete list. There seems to be no way of changing this ordering as of now. Would be nice to be able to customize them.<br />
&nbsp;<br />
<img src="http://www.seifi.org/wp-content/uploads/2008/09/omnibar.gif" alt="" title="Google Chrome Omnibar - Search Amazon" width="396" height="173" /><br />
&nbsp;</p>
<ol>
<li>Search Google for FOOBAR</li>
<li>FOOBAR/ (I&#8217;m not sure how useful this one is really)</li>
<li>Link to the FOOBAR Wikipedia page</li>
<li>Link to I&#8217;m Feeling Lucky URL for term FOOBAR. This item gives you the ability to search within the URL. For example if you type in Amazon in the Omnibar and select the amazon.com option using the down arrows, you will see &#8220;Press Tab to Search Amazon&#8221;. See below instruction on implementing this search functionality for your website.
</li>
<li>Search Google for FOOBAR ANOTHER TERM</li>
<li>Search Google for FOOBAR ANOTHER TERM</li>
<li>A page in your history pertaining to FOOBAR</li>
<li>Link to history search for pages about FOOBAR</li>
</ol>
</li>
</ul>
<h3>Cool Developer related stuff in Chrome</h3>
<p>Google Chrome User Agent String: </p>
<blockquote><p>Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.X.Y.Z Safari/525.13.</p></blockquote>
<p>Chrome has a menu option called &#8220;Create application shortcuts&#8230;&#8221; that uses Google Gears to create a shortcut to your webapp. Users can choose to place the shortcut to your webapp on their Desktop, on the Start menu and even the Quick launch bar in Windows. This is a pretty powerful feature. When a user clicks this icon, Chrome opens up without the Omnibar, and your website will appear in an &#8220;Application&#8221; format. You can customize how Chrome creates these shortcuts using meta tags. These tags are named: application-name, description, application-url, and shortcut icons in both 32&#215;32 or 48&#215;48 formats. The favicon is used if not specified. For example you can use the following HTML code in the head of your document. Note that with the Mozilla added support which is used in Chrome, you can use any supported graphic format as your favicon, and not just the old school <a href="http://en.wikipedia.org/wiki/Favicon">favicon.ico</a> file.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;head&gt;
  &lt;meta name=&quot;application-name&quot; content=&quot;Gmail&quot;/&gt;
  &lt;meta name=&quot;description&quot; content=&quot;Google's approach to email&quot;/&gt;
  &lt;meta name=&quot;application-url&quot; content=&quot;http://www.gmail.com&quot;/&gt;
  &lt;link rel=&quot;icon&quot; href=gmail_32x32.png sizes=&quot;32x32&quot;/&gt;
  &lt;link rel=&quot;icon&quot; href=gmail_48x48.png sizes=&quot;48x48&quot;/&gt;
&lt;/head&gt;</pre></div></div>

<p>To open a new tab from your webapp in a separate process using JavaScript you can do this in Chrome.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> w <span style="color: #339933;">=</span> window.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
w.<span style="color: #660066;">opener</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
w.<span style="color: #660066;">document</span>.<span style="color: #660066;">location</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://differentsite.com/index.html&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Chrome lets users search your website from its ominbar. To enable and include your website&#8217;s search in Chrome you have to create an <a href="http://www.opensearch.org">OpenSearch</a> description document (OSDD).<br />
For example you can create something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;OpenSearchDescription</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://a9.com/-/spec/opensearch/1.1/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ShortName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Web Search<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ShortName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Use Example.com to search the Web.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Tags<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>example web<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Tags<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Contact<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>admin@example.com<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Contact<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Url</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;application/atom+xml&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">template</span>=<span style="color: #ff0000;">&quot;http://example.com/?q={searchTerms}&amp;amp;pw={startPage?}&amp;amp;format=atom&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Url</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;application/rss+xml&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">template</span>=<span style="color: #ff0000;">&quot;http://example.com/?q={searchTerms}&amp;amp;pw={startPage?}&amp;amp;format=rss&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Url</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/html&quot;</span> </span>
<span style="color: #009900;">        <span style="color: #000066;">template</span>=<span style="color: #ff0000;">&quot;http://example.com/?q={searchTerms}&amp;amp;pw={startPage?}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;LongName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Example.com Web Search<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/LongName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Image</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;64&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;64&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;image/png&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>http://example.com/websearch.png<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Image<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Image</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;16&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;16&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;image/vnd.microsoft.icon&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>http://example.com/websearch.ico<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Image<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Query</span> <span style="color: #000066;">role</span>=<span style="color: #ff0000;">&quot;example&quot;</span> <span style="color: #000066;">searchTerms</span>=<span style="color: #ff0000;">&quot;cat&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Developer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Example.com Development Team<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Developer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Attribution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
     Search data Copyright 2005, Example.com, Inc., All Rights Reserved
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Attribution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SyndicationRight<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>open<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SyndicationRight<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;AdultContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/AdultContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Language<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>en-us<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Language<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;OutputEncoding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>UTF-8<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/OutputEncoding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;InputEncoding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>UTF-8<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/InputEncoding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/OpenSearchDescription<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Fore more tips read the Google Chrome <a href="http://gears.google.com/chrome/intl/en/webmasters-faq.html">FAQ for web developers</a> page.</p>
<p>ps. Don&#8217;t use the <a href="http://gears.google.com/chrome/">Google gears Chrome download page</a> which gives a JavaScript error!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">_GU_SetupOneClick <span style="color: #000066; font-weight: bold;">is</span> not defined
<span style="color: #000066;">onload</span><span style="color: #009900;">&#40;</span>load <span style="color: #009900;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.seifi.org/javascript/google-chrome-first-impressions.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript Arguments</title>
		<link>http://www.seifi.org/javascript/javascript-arguments.html</link>
		<comments>http://www.seifi.org/javascript/javascript-arguments.html#comments</comments>
		<pubDate>Tue, 19 Aug 2008 23:16:20 +0000</pubDate>
		<dc:creator>Joe Seifi</dc:creator>
				<category><![CDATA[business]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.seifi.org/?p=673</guid>
		<description><![CDATA[The arguments object in JavaScript is a local variable in any function that provides some nice features we can use in our code. Here is the list of its properties and related properties of the Function object. arguments itself returns an object that looks like an array (but not really an array) of the arguments [...]]]></description>
			<content:encoded><![CDATA[<p>The arguments object in JavaScript is a local variable in any function that provides some nice features we can use in our code. Here is the list of its properties and related properties of the Function object.</p>
<p><code>arguments</code> itself returns an object that looks like an array (but not really an array) of the arguments passed to the function.</p>
<p>Prior to JavaScript 1.4 the <code>Function</code> object also had a similar <code>arguments</code> property, which is now deprecated.</p>
<p>However the Function object comes with a few other useful properties that we can still use to get argument related data.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> callTaker<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>b<span style="color: #339933;">,</span>c<span style="color: #339933;">,</span>d<span style="color: #339933;">,</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// arguments properties</span>
  console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>arguments.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>arguments.<span style="color: #660066;">callee</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>arguments<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #006600; font-style: italic;">// Function properties</span>
 console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>callTaker.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>callTaker.<span style="color: #660066;">caller</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>arguments.<span style="color: #660066;">callee</span>.<span style="color: #660066;">caller</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>arguments.<span style="color: #660066;">callee</span>.<span style="color: #660066;">caller</span>.<span style="color: #660066;">caller</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>callTaker.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>callTaker.<span style="color: #660066;">constructor</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> callMaker<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  callTaker<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;foo&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;bar&quot;</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span>document<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  callMaker<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>For demonstration purposes, you can <a href="" onclick="return initDemo();">run the init function</a> above and view the logs in FireBug.</p>
<h3>arguments object and its properties</h3>
<p><code><strong>arguments</strong></code> returns ["foo", "bar", Window, Document]</p>
<p><code><strong>arguments.length</strong></code> returns 4</p>
<blockquote class="note"><p>Note: even though our function has a signature with 5 arguments, length returns only 4 here. This is because the caller sent us only 4 arguments. See below for how we can use Function&#8217;s length property to find the number of expected arguments.</p></blockquote>
<p><code><strong>arguments.callee</strong></code> returns callTaker(a, b, c, d, e)</p>
<blockquote class="note"><p>Note: callee shows us the signature of the currently executing function and is useful when trying to make recursive calls to a function within its own body.</p></blockquote>
<p><code><strong>arguments[1]</strong></code> returns bar</p>
<blockquote class="note"><p>Note: arguments can also be set for functions in an array like format. For example you can set the second argument like this: <code><strong>arguments[1] = 'moo';</strong></code>
</p></blockquote>
<h3>Function object and its argument related properties</h3>
<p><code><strong>callTaker.length</strong></code> returns 5</p>
<blockquote class="note"><p>Note: This is the expected number of arguments.</p></blockquote>
<p><code><strong>callTaker.caller</strong></code> is the same as <code><strong>arguments.callee.caller</strong></code> and returns callMaker()</p>
<blockquote class="note"><p>Note: we can go up the stack trace and get the caller of the caller etc. For example we can find the function that called callMaker using <code>arguments.callee.caller.caller</code> which returns init().</p></blockquote>
<p><code><strong>callTaker.name</strong></code> returns callTaker</p>
<p><code><strong>callTaker.constructor</strong></code> returns Function()</p>
<blockquote class="note"><p>Note: Since we have not modified the basic behavior, we see the built in function that creates an object&#8217;s prototype for our function, which is the Function object.
</p></blockquote>
<h3>Basic Usage Sample</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> dataArray <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;One&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;Two&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;Three&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;Four&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> lister <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> createList<span style="color: #009900;">&#40;</span>list<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>arguments.<span style="color: #660066;">length</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> result <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;&quot;</span> <span style="color: #339933;">+</span> arguments<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> arguments<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   result <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;&lt;li&gt;&quot;</span> <span style="color: #339933;">+</span> arguments<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  result <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;&lt;/&quot;</span> <span style="color: #339933;">+</span> arguments<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;l&gt;&quot;</span><span style="color: #339933;">;</span>
  document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>arguments<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> result<span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> makeList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 lister<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;list_HTML&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;ul&quot;</span><span style="color: #339933;">,</span>dataArray<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><a href="" onclick="return makeListDemo();">Run the sample</a><br />
<span id="list_HTML"></span></p>
<p>References:<br />
<a href="http://eriwen.com/javascript/js-stack-trace/" target="_blank">JavaScript Stack Trace</a><br />
<a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Function" target="_blank">Function</a><br />
<a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Functions:arguments" target="_blank">arguments</a></p>
<style>code strong{color:#F24C8B;font-family:verdana;font-weight:normal;}blockquote.note{margin:0 0 10px;}</style>
<p><script src="http://www.seifi.org/wp-content/uploads/2008/08/arguments.js"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.seifi.org/javascript/javascript-arguments.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Whats new in Safari 3.1 Web Inspector and Snippet Editor</title>
		<link>http://www.seifi.org/css/whats-new-in-safari-31-web-inspector-and-sinppet-editor.html</link>
		<comments>http://www.seifi.org/css/whats-new-in-safari-31-web-inspector-and-sinppet-editor.html#comments</comments>
		<pubDate>Fri, 21 Mar 2008 23:10:03 +0000</pubDate>
		<dc:creator>Joe Seifi</dc:creator>
				<category><![CDATA[apple]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.seifi.org/testing/whats-new-in-safari-31-web-inspector-and-sinppet-editor.html</guid>
		<description><![CDATA[Safari 3.1 features improvements to the functionality for the Web Inspector developers tool. In now has an improved console for working with JavaScript and DOM, DOM inspector with CSS support, a nice Network analysis tool and search all built in. It is somewhat comparable to the FireBug plugin for FireFox so I will also make [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.seifi.org/browsers/safari-31-features.html">Safari 3.1 features improvements</a> to the functionality for the Web Inspector developers tool. In now has an improved console for working with JavaScript and DOM, DOM inspector with CSS support, a nice Network analysis tool and search all built in. It is somewhat comparable to the <a href="http://www.seifi.org/firebug/firebug_tips_and_tricks.html">FireBug plugin for FireFox</a> so I will also make some comparisons of their features.<br />
<span id="more-636"></span></p>
<h3>Web Inspector Overview</h3>
<p><img src='http://www.seifi.org/wp-content/uploads/2008/03/web_inspector_nav.gif' alt='Web Inspector Navigation' align="right" hspace="10" /> To get started open Web Inspector by going to Safari 3.1/Develop/Show Web Inspector and you will see the new window open up. The initial window is split up into a top row with navigation buttons and search box. The navigation buttons take you the the next and last actions you make within Web Inspector and come in handy when debugging. The left navigation lets you view and inspect the loaded web resources including Documents, StyleSheets, Images, Scripts, WebFonts, Databases and Other files, as well as buttons to load the Console and Network details. Ajax request and responses show up under the Other file category. If any errors are found, the number of errors are placed on the file name in the navigator. For example here, Safari has found 1 bug in the file diggthis.js The main content area shows you the web source details for viewing. JavaScript errors are marked with an orange pop, while HTML and CSS errors have a red color. If you want to attach Web Inspector to the bottom of your Safari Window click the small box on the bottom left corner of the window. I found this this to be a more usable placement.</p>
<h3>DOM Editing</h3>
<p>Clicking on any HTML Document on the left loads the source on the right. Documents can also be viewed as a DOM resrouce by clicking ont he DOM button on the top nav. (Note you have flip between DOM and Source view for HTML files.)</p>
<p><img src='http://www.seifi.org/wp-content/uploads/2008/03/webinspector_dom_search.gif' alt='DOM Editing' align="right" hspace="10" /> Searching supports DOM and CSS elements and you can nest your DOM element searches to filter out exactly what you&#8217;re looking for. For example #page a returns all anchor tags in the div with the page id. The corresponding display element in Safari is highlighted as you select DOM elements.</p>
<p>The right pane displays Styles, Metrics and Properties for seleted DOM elements. Styles show you both the computed style as well as all the defined style rules for that object. Like FireBug you can edit your CSS rules in real time in the Styles boxes for each CSS rule. To edit any CSS property double click the name or value and an edit box opens allowing you to type in your changes. This is great for testing out new ideas on the fly.</p>
<p>The metrics pane shows you the layout rules including offset, margin, border, padding, width and height for the element. Finally the Properties pane lists all of the DOM object properties that apply to the selected element.</p>
<h3>Downloadable Web Fonts</h3>
<p>If you are using downloadable web fonts the Fonts file group shows you a rendering of all the fonts that are loaded into the user&#8217;s browser.<img src='http://www.seifi.org/wp-content/uploads/2008/03/webfonts.gif' alt='Downloadble Web Fonts' /></p>
<h3>Client Side Databases</h3>
<p>Also if you are using the client side database features of HTML5, the Databases category will let your explore the databases loaded in the client along with the all the tables and rows in each client side database. From here you can also execute SQL queries against the databases.<img src='http://www.seifi.org/wp-content/uploads/2008/03/databases.gif' alt='Client Side Databases' /></p>
<h3>The Console</h3>
<p>The console feature lets you type in JavaScript commands and view JavaScript errors, along with HTML and CSS rule errors. Clicking on any error jumps to the file, but unfortunately doesn&#8217;t go the corresponding line. The console has an input area for testing out JavaScript and DOM commands on the bottom. There is in fact a console object and my tests showed that Safari supports only a few of the <a href="http://www.getfirebug.com/console.html" target="_blank">functions</a> for the console object. Here is a list of the FireBug console methods of which only a few are supported in Safari namely log, info, warn and error.</p>
<blockquote><p>
<strong>Supported methods:</strong><br />
log info warn error<br />
<strong>Unsupported methods:</strong><br />
debug assert dir dirxml trace group groupEnd time timeEnd profile profileEnd count
</p></blockquote>
<p><img src='http://www.seifi.org/wp-content/uploads/2008/03/console.gif' alt='Safari Console' /></p>
<h3>Network</h3>
<p>The network tab is actually quite nicely designed and show you what the transfer time or the transfer size for each resource and in total for the page. The capsule graph is color coded and breaks down the file types by Docs, CSS, Images, Script and Other. You can switch between time or size from the drop down. Web Inspector makes some suggestions as well for improving speed, for example here we see a recommendation to use file compression to save bandwidth. (I don&#8217;t really use this method now since IE6 is buggy with gzip deflation.) Click on any file to see the HTTP request and response header for that file.<br />
<img src='http://www.seifi.org/wp-content/uploads/2008/03/network.gif' alt='Network tool in Safari' /></p>
<h3>Snippet Editor</h3>
<p>The Snippet Editor is a little utility that allows you to enter blocks of HTML and CSS and have it rendered on the fly. It is quite useful for testing out your CSS and Layout in little chunks.<br />
<img src='http://www.seifi.org/wp-content/uploads/2008/03/snippet_editor.png' alt='Snippet Editor' /></p>
<p>Note: While using the Web Inspector and Snippet Editor, I came across numerous little annoying bugs and usability issues here and there. Also lots of features that I would expect are not there. For example you can not click on elements to inspect them, you can not add new style rules if they don&#8217;t exist already, and you can&#8217;t edit rules for CSS files loaded using @import. I would have to say that <a href="http://www.seifi.org/firebug/firebug_tips_and_tricks.html">FireBug</a> is a superior tool at this time for professional debugging, but Safari is about half way there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seifi.org/css/whats-new-in-safari-31-web-inspector-and-sinppet-editor.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Safari 3.1 Features Review</title>
		<link>http://www.seifi.org/css/safari-31-features.html</link>
		<comments>http://www.seifi.org/css/safari-31-features.html#comments</comments>
		<pubDate>Wed, 19 Mar 2008 20:47:40 +0000</pubDate>
		<dc:creator>Joe Seifi</dc:creator>
				<category><![CDATA[apple]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.seifi.org/browsers/safari-31-features.html</guid>
		<description><![CDATA[Apple released Safari 3.1 (525.13) for both Mac and Windows users today which comes with a bunch of changes and improvements over 3.0.x series. Here are the set of changes included in the new release. Developer Menu The first thing you will notice is the addition of the &#8220;Develop&#8221; menu (Preferences/Advanced/Show Develop menu in menu [...]]]></description>
			<content:encoded><![CDATA[<p>Apple released <a href="http://www.apple.com/safari/" target="_blank">Safari 3.1</a> (525.13) for both Mac and Windows users today which comes with a bunch of changes and <a href="http://docs.info.apple.com/article.html?artnum=307467" target="_blank">improvements</a> over 3.0.x series. Here are the set of changes included in the new release.</p>
<h3>Developer Menu</h3>
<p>The first thing you will notice is the addition of the &#8220;<strong>Develop</strong>&#8221; menu (Preferences/Advanced/Show Develop menu in menu bar) item with the following tasks:<br />
<span id="more-630"></span><br />
<img src="http://www.seifi.org/wp-content/uploads/2008/03/safari_develop_menu.png" title="Safari Developer Menu" alt="Safari Developer Menu" align="right" hspace="15" vspace="5" /> Open Page with: (Other browsers installed on your system including FireFox, Internet Explorer, Opera)</p>
<p>User Agent: Set you user agent from the list of options, or enter your own user-agent. Finally! This was previously part of the hidden debug menu and you had no way of specifying a custom user-agent. The other exciting additions here are the ability to set your user-agent as Mobile Safari 1.1.3 for either iPhone or the iPod touch.</p>
<p>You can also pull up the Web Inspector, Error console, Network Timeline and a Snippet Editor. Lastly the Developer menu allows you to disable various browser features such as Caches, Images, CSS Styles, JavaScript, Runaway JavaScript Timers, and Site-Specific Hacks. You can now also edit CSS in the Web Inspector. More on these in a <a href="http://www.seifi.org/testing/whats-new-in-safari-31-web-inspector-and-sinppet-editor.html">later post</a>.</p>
<h3>Standards Support</h3>
<p>Support for <a href="http://www.w3.org/TR/css3-webfonts/" target="_blank">CSS 3 web fonts</a> using CSS @font-face rules. check out <a href="http://www.alistapart.com/articles/cssatten" target="_blank">what can be done</a> with downloadable fonts in these working samples <a href="http://www.alistapart.com/d/cssatten/heid.html" target="_blank">here</a>, <a href="http://www.alistapart.com/d/cssatten/poen.html" target="_blank">here</a>, <a href="http://www.alistapart.com/d/cssatten/nels.html" target="_blank">here</a>, <a href="http://www.alistapart.com/d/cssatten/stef.html" target="_blank">here</a>, <a href="http://www.alistapart.com/d/cssatten/blok.html" target="_blank">here</a>, and <a href="http://www.alistapart.com/d/cssatten/drim.html" target="_blank">here</a>. The CSS and a sample web font are show below. If you are using Safari 3.1 you should see a cool font.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #a1a100;">@font-face {</span>
  <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;Acorn Initials&quot;</span><span style="color: #00AA00;">;</span>
  src<span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span>http<span style="color: #00AA00;">:</span>//www<span style="color: #6666ff;">.domain</span>.com/Acorn___.ttf<span style="color: #00AA00;">&#41;</span> format<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;truetype&quot;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<style type="text/css" media="all">
@import "/wp-content/uploads/2008/03/webfonts.css";
</style>
<h1 id="webfonts">Safari 3.1</h1>
<p>Support for CSS <a href="http://webkit.org/blog/130/css-transforms/" target="_blank">transforms</a> and <a href="http://webkit.org/blog/138/css-animation/" target="_blank">transitions</a>. Below are some demos of these.</p>
<div style="width:85%;margin:0 auto 10px auto;padding:8px;">
<img hspace="20" vspace="5" align="left" src="http://www.seifi.org/wp-content/uploads/2008/03/safari_logo.png" alt="Safari 3.1" style="-webkit-transition:-webkit-transform 1.5s ease-in;" onclick="this.style.webkitTransform='rotate(1440deg)';" /> Here is a sample of the -webkit transform CSS which is now supported by Safari 3.1. Click on the Safari logo to rotate it 1440 degrees.<br />
<br style="clear:both" /></p>
<p><img hspace="20" vspace="5" align="left" src="http://www.seifi.org/wp-content/uploads/2008/03/safari_logo.png" alt="Safari 3.1" style="-webkit-transform: skew(35deg, 0deg);" /> The following Safari logo is skewed 35 degrees using -webkit-transform: skew(45deg, 0deg).<br />
<br style="clear:both" /></p>
<p><img hspace="20" vspace="5" align="left" src="http://www.seifi.org/wp-content/uploads/2008/03/safari_logo.png" alt="Safari 3.1" style="" onmouseover="this.style.webkitTransform='scale(1.3)'" onmouseout="this.style.webkitTransform='scale(1)'" /> The following image changes its scale using -webkit transform:scale() to zoom in 30% when you mouse over it.<br />
<br style="clear:both" />
</div>
<p>Support for <a href="http://www.whatwg.org/specs/web-apps/current-work/" target="_blank">HTML 5</a> &lt;<a href="http://www.whatwg.org/specs/web-apps/current-work/#video" target="_blank">video</a>&gt; and &lt;<a href="http://www.whatwg.org/specs/web-apps/current-work/#audio" target="_blank">audio</a>&gt; elements. Watch out Adobe and Flash. Here is a <a href="http://webkit.org/blog/140/html5-media-support/" target="_blank">demo</a> of the video tag. There is also added support for SVG images in &lt;img&gt; elements and CSS images and SVG advanced text.</li>
<p>Support for <a href="http://www.whatwg.org/specs/web-apps/current-work/#offline" target="_blank">offline</a> storage for Web applications in <a href="http://www.whatwg.org/specs/web-apps/current-work/#sql" target="_blank">SQL databases</a>. That means you can now store your databases locally on the client&#8217;s machine. Here&#8217;s some sample JavaScript to do the client side databases. Check out <a href="http://webkit.org/misc/DatabaseExample.html" target="_blank">this demo</a> that shows you how it works.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">database.<span style="color: #660066;">executeSql</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;SELECT * FROM test&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>result1<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #006600; font-style: italic;">// do something with the results</span>
   database.<span style="color: #660066;">executeSql</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;DROP TABLE test&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>result2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #006600; font-style: italic;">// do some more stuff</span>
     <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;My second database query finished executing!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>&nbsp;<br />
Running the <a href="http://www.css3.info/selectors-test/" target="_blank">CSS3 Selector tests</a> reveals that Safari 3.1 has full support for CSS3 Selectors while FireFox 2 and IE 7 are still playing catch up.<br />
<img src="http://www.seifi.org/wp-content/uploads/2008/03/css3_support.png" alt="JavaScript Test Results" /></p>
<h3>Performance Improvements</h3>
<p>Apple claims that Safari 3.1 &#8220;executes JavaScript up to 6 times faster than Internet Explorer 7 and up to 4 times faster than Firefox 2&#8243;. Performance measured in seconds. Testing conducted by Apple in March 2008 on a 2.4GHz Intel Core 2 Duo-based iMac system running Windows XP Professional SP2, configured with 1GB of RAM and an ATI Radeon HD 2600 with 256MB of VRAM. HTML and JavaScript benchmarks based on VeriTest’s iBench Version 5.0 using default settings. Testing conducted with a beta version of Safari; all other browsers were shipping versions. Performance will vary based on system configuration, network connection, and other factors.&#8221; I tested IE7, FF2, and Safari 3.1 with 3 JavaScript performance testers and the Acid 3 test kit. The tools used are<br />
1. <a href="http://acid3.acidtests.org/" target="_blank">Acid3</a> tests.<br />
2. <a href="http://www.jorendorff.com/articles/javascript/speed-test.html" target="_blank">JavaScript speed test</a> written by Jason Orendorff<br />
3. <a href="http://webkit.org/perf/sunspider-0.9/sunspider.html" target="_blank">SunSpider</a> test kit from WebKit.org<br />
4. <a href="http://mootools.net/slickspeed/" target="_blank">slickspeed</a> test from Mootools.net</p>
<p>Here are the results in milliseconds from the tests which seem to agree with the results found by Apple. You can see that Safari 3.1 does in fact have a much more efficient JavaScript processing engine, and is three quarters of the way there when comes to passing the Acid3 tests.<br />
<img src="http://www.seifi.org/wp-content/uploads/2008/03/js_test_results.png" alt="JavaScript Test Results" /><br />
<small>Detail links at SunSpider: &nbsp; <a target="_blank" href="http://webkit.org/perf/sunspider-0.9/sunspider-results.html?%7B%223d-cube%22:%5B581,511,611,531,541%5D,%223d-morph%22:%5B561,591,591,631,611%5D,%223d-raytrace%22:%5B701,691,701,711,711%5D,%22access-binary-trees%22:%5B691,701,701,590,701%5D,%22access-fannkuch%22:%5B1132,1122,1102,1072,1362%5D,%22access-nbody%22:%5B570,561,550,550,1071%5D,%22access-nsieve%22:%5B571,571,571,571,1082%5D,%22bitops-3bit-bits-in-byte%22:%5B561,560,561,561,1152%5D,%22bitops-bits-in-byte%22:%5B621,621,621,631,1212%5D,%22bitops-bitwise-and%22:%5B731,731,741,731,852%5D,%22bitops-nsieve-bits%22:%5B581,581,581,581,621%5D,%22controlflow-recursive%22:%5B701,711,712,711,721%5D,%22crypto-aes%22:%5B561,571,561,561,571%5D,%22crypto-md5%22:%5B521,521,531,521,510%5D,%22crypto-sha1%22:%5B460,560,480,460,571%5D,%22date-format-tofte%22:%5B681,631,571,571,611%5D,%22date-format-xparb%22:%5B671,641,611,611,621%5D,%22math-cordic%22:%5B711,701,701,681,701%5D,%22math-partial-sums%22:%5B481,481,471,471,471%5D,%22math-spectral-norm%22:%5B541,521,530,530,530%5D,%22regexp-dna%22:%5B531,530,551,541,551%5D,%22string-base64%22:%5B19198,19338,19007,24445,32326%5D,%22string-fasta%22:%5B641,671,731,761,1312%5D,%22string-tagcloud%22:%5B3605,3705,3576,7872,3635%5D,%22string-unpack-code%22:%5B651,651,701,651,731%5D,%22string-validate-input%22:%5B10765,10736,10526,15542,21941%5D%7D">IE7</a> &nbsp;  &nbsp; <a  target="_blank" href="http://webkit.org/perf/sunspider-0.9/sunspider-results.html?%7B%223d-cube%22:%5B1342,1211,1192,1201,1212%5D,%223d-morph%22:%5B1742,1743,1762,1702,1733%5D,%223d-raytrace%22:%5B591,591,621,571,581%5D,%22access-binary-trees%22:%5B350,571,650,681,751%5D,%22access-fannkuch%22:%5B701,681,621,610,611%5D,%22access-nbody%22:%5B1442,1442,1412,1412,1412%5D,%22access-nsieve%22:%5B360,331,340,381,370%5D,%22bitops-3bit-bits-in-byte%22:%5B481,451,471,481,481%5D,%22bitops-bits-in-byte%22:%5B461,460,461,460,451%5D,%22bitops-bitwise-and%22:%5B3555,3565,3525,3455,4536%5D,%22bitops-nsieve-bits%22:%5B581,611,600,581,1152%5D,%22controlflow-recursive%22:%5B201,190,301,250,540%5D,%22crypto-aes%22:%5B531,511,511,501,681%5D,%22crypto-md5%22:%5B381,411,461,411,831%5D,%22crypto-sha1%22:%5B581,510,541,520,571%5D,%22date-format-tofte%22:%5B1402,1212,1042,1042,1121%5D,%22date-format-xparb%22:%5B2243,2123,2193,2053,2093%5D,%22math-cordic%22:%5B1272,1091,1192,1152,1221%5D,%22math-partial-sums%22:%5B842,841,821,841,821%5D,%22math-spectral-norm%22:%5B601,561,540,541,571%5D,%22regexp-dna%22:%5B1062,1161,1142,1141,1132%5D,%22string-base64%22:%5B1092,1092,1081,1092,1072%5D,%22string-fasta%22:%5B921,831,841,842,871%5D,%22string-tagcloud%22:%5B791,681,681,721,761%5D,%22string-unpack-code%22:%5B1111,1082,1132,1192,1072%5D,%22string-validate-input%22:%5B621,641,631,651,661%5D%7D">FireFox 2.2</a> &nbsp;  &nbsp; <a  target="_blank" href="http://webkit.org/perf/sunspider-0.9/sunspider-results.html?%7B%223d-cube%22:%5B250,300,280,281,171%5D,%223d-morph%22:%5B170,291,291,271,331%5D,%223d-raytrace%22:%5B321,271,271,271,290%5D,%22access-binary-trees%22:%5B211,191,180,190,210%5D,%22access-fannkuch%22:%5B511,451,490,500,501%5D,%22access-nbody%22:%5B280,280,311,321,291%5D,%22access-nsieve%22:%5B180,90,221,221,231%5D,%22bitops-3bit-bits-in-byte%22:%5B221,220,211,211,80%5D,%22bitops-bits-in-byte%22:%5B140,120,121,131,311%5D,%22bitops-bitwise-and%22:%5B361,390,381,381,370%5D,%22bitops-nsieve-bits%22:%5B241,251,250,250,240%5D,%22controlflow-recursive%22:%5B191,251,240,240,240%5D,%22crypto-aes%22:%5B221,251,250,250,250%5D,%22crypto-md5%22:%5B231,240,240,150,251%5D,%22crypto-sha1%22:%5B250,90,250,210,100%5D,%22date-format-tofte%22:%5B350,350,291,301,331%5D,%22date-format-xparb%22:%5B370,370,431,381,381%5D,%22math-cordic%22:%5B391,411,310,420,410%5D,%22math-partial-sums%22:%5B330,341,421,320,311%5D,%22math-spectral-norm%22:%5B280,280,201,291,201%5D,%22regexp-dna%22:%5B491,491,550,480,441%5D,%22string-base64%22:%5B240,241,261,230,220%5D,%22string-fasta%22:%5B360,350,371,331,330%5D,%22string-tagcloud%22:%5B271,251,251,270,281%5D,%22string-unpack-code%22:%5B270,350,350,280,280%5D,%22string-validate-input%22:%5B210,330,340,291,290%5D%7D">Safari 3.1</a></small></p>
<h3>Microsoft Windows</h3>
<ul>
<li>Improves Back/Forward performance</li>
<li>Supports signed Java applets</li>
<li>Shows Caps Lock icon in password fields</li>
<li>Adds support for showModalDialog</li>
<li>Localized in 16 languages</li>
<li>Adds support for International Domain Names</li>
<li>Improves handling of Japanese, Chinese, and Korean text</li>
<li>Contextual menu now allows opening a link in a window or tab</li>
<li>Improves pop-up blocking to work with plug-ins</li>
</ul>
<h3>Other Improvement</h3>
<ul>
<li>Double clicking on the Tab Bar opens new tab</li>
<li>Includes URL metadata when images are dragged or saved from browser</li>
<li>Opens Download and Activity window in current Space</li>
<li>Supports trackpad gestures for back, forward, and magnify on MacBook Air and compatible MacBook Pro computers</li>
<li>Shows Caps Lock icon in password fields</li>
<li><a href="http://docs.info.apple.com/article.html?artnum=307563" target="_blank">13 Security Fixes</a></li>
<li>Increased site compatibility</li>
<li>Improved application stability</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.seifi.org/css/safari-31-features.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How Google Analytics determines Connection Speeds</title>
		<link>http://www.seifi.org/javascript/how-google-analytics-determines-connection-speeds.html</link>
		<comments>http://www.seifi.org/javascript/how-google-analytics-determines-connection-speeds.html#comments</comments>
		<pubDate>Wed, 12 Mar 2008 18:43:55 +0000</pubDate>
		<dc:creator>Joe Seifi</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[stats]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.seifi.org/ajax/how-google-analytics-determines-connection-speeds.html</guid>
		<description><![CDATA[Today I was looking for an unobtrusive method of determining a user&#8217;s connection speed using JavaScript. A quick search on Google returned an array of tricks mostly having to do with using Ajax to make a call behind the scenes, and track the payload time for the small file. In most cases people use an [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was looking for an unobtrusive method of determining a user&#8217;s connection speed using JavaScript. A quick <a href="http://www.google.com/search?q=javascript+connection+speed" target="_blank">search</a> on Google returned an array of <a href="http://myspeed.ebiene.de/" target="_blank">tricks</a> mostly having to do with using Ajax to make a call behind the scenes, and track the payload time for the small file. In most cases people use an image with a random variable at the end to avoid caching, like image.jpg?foo=1Rt2X21. This is all good but adds an HTTP connection which could potentially interfere with the user&#8217;s experience, especially if they are already on a slow connection to begin with.<span id="more-627"></span></p>
<p>Then I discovered something interesting in <a href="https://www.google.com/analytics/" target="_blank">Google Analytics</a>.</p>
<p>Google Analytics tracks and stores connection speeds for your visitors as part of the Network Properties category. The data provided includes Connection Speed and this corresponds with Pages per visit, Average time on Site, Percentage of new visits, and the Bounce rate. But how in the world does Google compile this data? It <a href="http://groups.google.com/group/analytics-help-basics/browse_thread/thread/c3c01931dcdcf1d/07a492c88916f80e?lnk=gst&amp;q=speed#07a492c88916f80e" target="_blank">appears</a> that people are <a href="http://informationgift.com/2006/10/analytics_guesses_connection_s.html" target="_blank">guessing</a> that Google uses the visitor&#8217;s IP address or hostname to do a lookup in an IP database or a <a href="http://groups.google.com/group/analytics-help-tracking/browse_thread/thread/9206114c0909379e/078a201bc3e9b566?lnk=gst&amp;q=speed#078a201bc3e9b566" target="_blank">reverse lookup</a>, and then makes a guess based on what ISP that IP address belongs to. But Google also loads a small .gif file with each <a href="http://www.google.com/support/urchin45/bin/answer.py?answer=28307" target="_blank">urchin</a> request. This article explains a little trick for using time stamped image loading and <a href="http://www.die.net/musings/page_load_time/" target="_blank">log analysis</a> which seems related.</p>
<p><img src="http://www.seifi.org/wp-content/uploads/2008/03/analyticsconnectionspeeds.gif" alt="Google Analytics Connection Speeds" /></p>
<p>So if your IP belongs to RoadRunner, then we can assume you are on a cable connection and file you under that category. This can sometimes get somewhat hairy and lead to ambiguity as evidenced by the Unknown category shown in Google Analytics. It is also interesting to note the Unknown category is the single largest category in my case with 36% of the total data collected. What happens if you are on AOL or EarthLink? Will the database contain the accurate information to pinpoint if you are on dial-up or broadband? How often is the database updated with new information? What about edge cases, for example if you work in an office where you have a &#8220;broadband&#8221; connection but share it with a large group of people?</p>
<p>The good news is that with Analytics the work happens without interfering with the user experience and no additional HTTP connections are needed. The bad news is, it is not done in real time. So if you are looking for a real-time test this will not work for you, unless you build your own seriously fast IP database web service that you can use asynchronously. The other option is to use the binary image payload test, but that also makes life hard for your users.</p>
<p>So, If you are looking for general statistics for a webapp over a date range then Google Analytics might be the way to go. Keep in mind you will end up with a chunk of Unknown data. As for making snap decisions, you can sniff user bandwidth while they surf with payload testing. Here is another sample <a href="http://site.aol.com/speed.html" target="_blank">page at AOL</a> where they put up a simple fork page and determine your bandwidth speed using JavaScript image loading and setting a user cookie. I can think of a dozen reasons why this is a bad idea but I won&#8217;t go into that here.</p>
<p><!--Content type: SDKML. Transform: wc2mtps.xslt.-->PS. It is worth mentioning that Internet Explorer supports a built in behavior called clientCaps, which provides information about features supported by Microsoft Internet Explorer, as well as a way for installing browser components on demand. The <a href="http://msdn2.microsoft.com/en-us/library/ms531088(VS.85).aspx" target="_blank">connectionType</a> property of clientCaps returns either <strong>lan</strong>, <strong>modem </strong>or <strong>offline</strong>. Since this only works in IE and doesn&#8217;t offer too much granularity, it might be a good test if you are <em>only trying to test IE users specifically</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seifi.org/javascript/how-google-analytics-determines-connection-speeds.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Aspen Simulator &#8211; Simulates iPhone Safari Browser</title>
		<link>http://www.seifi.org/javascript/aspen-simulator-simulates-iphone-safari-browser.html</link>
		<comments>http://www.seifi.org/javascript/aspen-simulator-simulates-iphone-safari-browser.html#comments</comments>
		<pubDate>Tue, 11 Mar 2008 04:52:21 +0000</pubDate>
		<dc:creator>Joe Seifi</dc:creator>
				<category><![CDATA[apple]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.seifi.org/iphone/aspen-simulator-simulates-iphone-safari-browser.html</guid>
		<description><![CDATA[The latest release of the iPhone SDK from Apple comes with an array of new Mac utilities for developing iPhone specific software. One of the new tools included with the iPhone SDK beta is the Aspen Simulator. Aspen is an iPhone simulator that developers can test their apps on which emulates all of the the [...]]]></description>
			<content:encoded><![CDATA[<p>The latest <a href="http://www.seifi.org/iphone/thoughts-on-app-store-and-cocoa-touch-for-iphone.html">release</a> of the iPhone SDK from Apple comes with an array of new Mac utilities for developing iPhone specific software. One of the new tools included with the iPhone SDK beta is the Aspen Simulator. Aspen is an iPhone simulator that developers can test their apps on which emulates all of the the features and functionality of the iPhone. For example you can use the mouse to swipe the page up, down, even pinch and more.<span id="more-623"></span>The Aspen Simulator app is located in the folder: <small>/Developer/Platforms/AspenSimulator.platform/Developer/Applications </small><a href="http://www.seifi.org/wp-content/uploads/2008/03/aspen_simulator.png" title="Aspen Simulator" rel="lightbox"><img src="http://www.seifi.org/wp-content/uploads/2008/03/aspen_simulator.thumbnail.png" alt="Aspen Simulator" title="Aspen Simulator" align="left" border="0" hspace="10" vspace="10" /></a>and has a few of the basic iPhone apps including Contacts, Settings, and most importantly mobile Safari. Using mobile Safari is in Aspen Simulator is a nice way to test out your webapps and see how they would look like on the iPhone. The problem I have found so far in this release is that the user-agent of the Safari browser is not set as an iPhone. This is problematic if you are doing some sort of user-agent sniffing using JavaScript in your webapp in order to show the iPhone specifc version of your site. Here is a screenshot of the Safari in Aspen Simulator and the user agent string. I used a basic alert statemnet to get this and the value is:</p>
<blockquote><p>Mozilla/5.0 (Aspen Simulator; U; Aspen 1_2 like Mac OS X; en-us) AppleWebKit/525.7 (KHTML, like Gecko) Version/3.1 Mobile/5A147p Safari/5525.7</p></blockquote>
<p>This means if you load up sites that only look right on the iPhone they won&#8217;t render correctly on the Aspen Simulator. An example of this is the <a href="http://www.appsafari.com/fun/2375/ygo-ajax-flickr/" target="_blank">Yahoo Ajax Flickr</a> website designed specifically for the iPhone. This page renders correctly if you&#8217;re on an iPhone, but will show you the basic mobile version if it doesn&#8217;t see iPhone in your user-Agent. Next version of Aspen will hopefully have an option to easily edit the user agent string of the Safari browser. For reference the mobile Safari app is located in this folder:</p>
<p><small>/Developer/Platforms/AspenSimulator.platform/Developer/SDKs/AspenSimulator1.2.sdk/</small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.seifi.org/javascript/aspen-simulator-simulates-iphone-safari-browser.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sniff and Disable Firebug Howto (Gmail example)</title>
		<link>http://www.seifi.org/javascript/sniff-and-disable-firebug-howto-gmail-example.html</link>
		<comments>http://www.seifi.org/javascript/sniff-and-disable-firebug-howto-gmail-example.html#comments</comments>
		<pubDate>Wed, 28 Nov 2007 20:02:38 +0000</pubDate>
		<dc:creator>Joe Seifi</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.seifi.org/ajax/sniff-and-disable-firebug-howto-gmail-example.html</guid>
		<description><![CDATA[Here is a simple test to see if users have Firebug installed on their browsers. Obviously this would also weed out non-FireFox users. if &#40;window.console &#38;&#38; window.console.firebug&#41; &#123; alert&#40;&#34;found Firebug&#34;&#41;; &#125;else&#123; alert&#40;&#34;can't find Firebug&#34;&#41;; &#125; Demo: Sniff for FireBug You may have noticed this message in your Gmail homepage recently: The reason for that is [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple test to see if users have <a href="http://www.seifi.org/firebug/firebug_tips_and_tricks.html">Firebug</a> installed on their browsers. Obviously this would also weed out non-FireFox users.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">console</span> <span style="color: #339933;">&amp;&amp;</span> window.<span style="color: #660066;">console</span>.<span style="color: #660066;">firebug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;found Firebug&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;can't find Firebug&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span id="more-608"></span><br />
Demo: <a href="javascript:if(window.console &#038;&#038; window.console.firebug){alert('found Firebug');}else{alert('can\'t find Firebug');}">Sniff for FireBug</a></p>
<p>You may have noticed this message in your Gmail homepage recently:<br />
<img src='http://www.seifi.org/wp-content/uploads/2007/11/gmail_firebug_issue.gif' alt='Gmail Doesn’t Like Firebug' /></p>
<p>The reason for that is Firebug by default logs all XMLHttpRequests made for all the websites you visit. The problem is that the data that is logged never gets disposed of or cleared out.  Therefore, FireFox having to collect and store that information and the memory for Firefox will eventually get large enough that will cause your computer to start using paged cache. This will then make Gmail seem like you are swimming through molasses. Gmail by default seems to make 22 XMLHttpRequests when I load the main page. It then makes a new XMLHttpRequest every 30 seconds, to check for new emails, so in the span of 1 hour you will have 120 new Ajax calls tacked on. This is a nice feature of Gmail which makes life simple for its users (Notice there is no &#8220;Get new mail&#8221; button anywhere). But now every new Ajax call is another 1kb of data which adds to the memory usage and tacks on more CPU and RAM consumed by Firebug.</p>
<p>No need to worry though since, another nice feature of Firebug is that you can disable it on a domain name basis. </p>
<p><img src='http://www.seifi.org/wp-content/uploads/2007/11/disable_gmail_firebug.gif' alt='How to disable Firebug for any domain name ex) mail.google.com' align="left" hspace="10" vspace="3" /> To turn off Firebug for mail.google.com first open Firebug by hitting the green icon or F12. Click on the bug icon in the top left and choose the second option labeled &#8220;Disable Firebug for mail.google.com&#8221;. Now Firebug will be turned off and the green icon will be changed to a silver icon for this domain. You should notice a smoother and faster Gmail experience. You can also turn it back on by clicking on the link &#8220;Enable Firebug for this website&#8221;.</p>
<p><img src='http://www.seifi.org/wp-content/uploads/2007/11/allowedsites.gif' alt='Allowed Sites…' align="right" hspace="10" vspace="3" /> The other and better method of speeding up your Firefox and still keeping Firebug around, is to disable Firebug all together and enable it for specific sites that you are working on. To disable Firebug, again you click on the Bug icon and this time choose the first option &#8220;Disable Firebug&#8221;.<br />
Now visit any site that you would like to use Firebug on and then &#8220;right click&#8221; on the silver icon on the bottom and choose &#8220;Allowed Sites&#8230;&#8221; From here you can add the domain name for any sites you want to override. This makes your life easier and makes general surfing faster in FireFox, yet allows for using the powers of the almighty Firebug when needed.</p>
<p>If your application is similar to Gmail where XMLHttpRequests are called in a loop you may want to use the sniff script to warn users to disable Firebug for your domain as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seifi.org/javascript/sniff-and-disable-firebug-howto-gmail-example.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Simple AJAX Request and Response JavaScript</title>
		<link>http://www.seifi.org/javascript/simple-ajax-request-response-javascript.html</link>
		<comments>http://www.seifi.org/javascript/simple-ajax-request-response-javascript.html#comments</comments>
		<pubDate>Fri, 27 Jul 2007 02:43:37 +0000</pubDate>
		<dc:creator>Joe Seifi</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.seifi.org/ajax/simple-ajax-request-response-javascript.html</guid>
		<description><![CDATA[Here is the simple form of an AJAX call made to an XML document, parsing through the returned document and and grabbing the a specific node from the DOM. There is a try/catch clause to handle the 4 different sets of XMLHTTP objects for different browsers. The callback function is called once the response is [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the simple form of an AJAX call made to an XML document, parsing through the returned document and and grabbing the a specific node from the DOM. There is a try/catch clause to handle the 4 different sets of XMLHTTP objects for different browsers. The callback function is called once the response is returned as 4+200 and the response is rendered to the user. Below is the JavasScript code snippet. <span id="more-591"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> XMLHttpArray <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Msxml2.XMLHTTP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Msxml2.XMLHTTP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Microsoft.XMLHTTP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">function</span> createXMLHTTPObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> xmlhttp <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>XMLHttpArray.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
                        xmlhttp <span style="color: #339933;">=</span> XMLHttpArray<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                        <span style="color: #000066; font-weight: bold;">continue</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">return</span> xmlhttp<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #006600; font-style: italic;">////</span>
<span style="color: #003366; font-weight: bold;">function</span> AjaxRequest<span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span>callback<span style="color: #339933;">,</span>method<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> req <span style="color: #339933;">=</span> createXMLHTTPObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        req.<span style="color: #660066;">onreadystatechange</span><span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>req.<span style="color: #660066;">readyState</span> <span style="color: #339933;">!=</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>req.<span style="color: #000066;">status</span> <span style="color: #339933;">!=</span> <span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
                callback<span style="color: #009900;">&#40;</span>req<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        req.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>method<span style="color: #339933;">,</span>url<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        req.<span style="color: #660066;">setRequestHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'User-Agent'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'My XMLHTTP Agent'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        req.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #006600; font-style: italic;">////</span>
<span style="color: #003366; font-weight: bold;">function</span> AjaxResponse<span style="color: #009900;">&#40;</span>req<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> respXML<span style="color: #339933;">=</span>req.<span style="color: #660066;">responseXML</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>respXML<span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> respVAL<span style="color: #339933;">=</span>respXML.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'family'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>
.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'result'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;status&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">+=</span> respVAL<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #006600; font-style: italic;">////</span>
<span style="color: #003366; font-weight: bold;">function</span> ClearResponse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        mdiv<span style="color: #339933;">=</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;status&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        mdiv.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #006600; font-style: italic;">////</span>
<span style="color: #003366; font-weight: bold;">function</span> MakeRequst<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        AjaxRequest<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ajax.xml&quot;</span><span style="color: #339933;">,</span>AjaxResponse<span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;get&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #006600; font-style: italic;">////</span></pre></div></div>

<p></p>
<p>And our sample XML file looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;family</span> <span style="color: #000066;">result</span>=<span style="color: #ff0000;">&quot;successful ajax request &amp;amp; response!&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;parents<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;father</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Mike&quot;</span> <span style="color: #000066;">last</span>=<span style="color: #ff0000;">&quot;Brady&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mother</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Carol&quot;</span> <span style="color: #000066;">last</span>=<span style="color: #ff0000;">&quot;Martin&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/parents<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;children<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sons<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;son<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Greg<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/son<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;son<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Peter<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/son<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;son<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Bobby<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/son<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sons<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;daughters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;daughter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Marcia<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/daughter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;daughter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Jan<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/daughter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;daughter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Cindy<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/daughter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/daughters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/children<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;maid</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Alice&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/family<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p></p>
<p>Here is a working sample of this code.</p>
<div id="status" style="border:10px solid #eee;background:#ccc;width:300px;padding:10px 5px;margin:5px 0;">
</div>
<p><button onclick="return MakeRequst();">Ajax Request</button> <button onclick="return ClearResponse();">Reset</button><br />
<script type="text/javascript" src="http://www.seifi.org/apps/simpleajax/ajax.js"></script></p>
<p>Some things to note are:</p>
<p>I&#8217;m using a GET here, but yo can easily change that to a POST in the call to AjaxRequest.</p>
<p>The URL passed to AjaxRequest can contain parameters as needed.</p>
<p>You can handle other readyStates(0,1,2,3) and <a href="http://www.w3.org/Protocols/HTTP/HTRESP.html">HTTP status codes</a> as you wish using the onreadystatechange handle. </p>
<p>I am sending null since I am not posting anything back to the server, but you can swap that with your own Post data if you wish. To set that up you have to also add this line of code before you call send to set the proper <a href="http://w3.org/Protocols/HTTP/HTRQ_Headers.html">request headers</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">req.<span style="color: #660066;">setRequestHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Content-type'</span> <span style="color: #339933;">,</span> 
<span style="color: #3366CC;">'application/x-www-form-urlencoded'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p></p>
<p>The responseXML property is only available when the request is made to an XML document, so If you are using other document types (HTML,Text,CSV,JSON) you will not have access to this property. If you use anything other than XML data you will have access to the responseText property instead.</p>
<p>Once you have the handle to the responseXML property, you can traverse through the XML DOM like you would with any other DOM object and you can use all the <a href="http://developer.mozilla.org/en/docs/DOM:element">DOM element methods, properties and events</a> that you already know.</p>
<p>For example to get a list of all the sons in the family we can do:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">respSONS<span style="color: #339933;">=</span>respXML.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;son&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
respSonVals <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> x<span style="color: #339933;">&lt;</span>respSONS.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    respSonVals <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot; &quot;</span> <span style="color: #339933;">+</span> respSONS<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">firstChild</span>.<span style="color: #660066;">nodeValue</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p></p>
<p>Try <a href="" onclick="return getSons()">Get Son Names</a></p>
<div id="domvals" style="border:10px solid #eee;background:#ccc;width:300px;padding:10px 5px;margin-bottom:5px;">Results Go Here:</div>
]]></content:encoded>
			<wfw:commentRss>http://www.seifi.org/javascript/simple-ajax-request-response-javascript.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Boost Your JavaScript and CSS Performance</title>
		<link>http://www.seifi.org/css/how_to_boost_your_javascript_and_css_performance.html</link>
		<comments>http://www.seifi.org/css/how_to_boost_your_javascript_and_css_performance.html#comments</comments>
		<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>
		<dc:creator>Joe Seifi</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.seifi.org/css/how_to_boost_your_javascript_and_css_performance.html</guid>
		<description><![CDATA[Lines of markup code per website are growing at a hurried pace these days. JavaScript and CSS files are getting bigger by the day. But you want to keep your site lean and speedy and avoid from becoming slow and bloated. There are some basic techniques I use to optimize JavaScript files and the same [...]]]></description>
			<content:encoded><![CDATA[<p>Lines of markup code per website are growing at a hurried pace these days. JavaScript and CSS files are getting bigger by the day. But you want to keep your site lean and speedy and avoid from becoming slow and bloated. There are some basic techniques I use to optimize JavaScript files and the same ideas can be applied to CSS and HTML files as well. I&#8217;ll briefly cover 4 popular solutions, namely validating, joining, shrinking and compressing your markup source code.<span id="more-482"></span></p>
<h3><strong>1) Validate your code</strong></h3>
<p>Although JavaScript can be very forgiving when it comes to error handling, sloppy coding will come back to haunt you in the long run. So the first step is to validate your code. I use <a href="http://www.jslint.com/lint.html">JSLint</a> which scans JavaScript code for syntax errors and common mistakes and recommends fixes. JSLint piggy backs on <a href="http://www.mozilla.org/rhino/">Rhino</a> which is an implementation of JavaScript written in Java from <a href="http://www.mozilla.org/">Mozilla</a>. You can either use the <a href="http://www.jslint.com/">online version</a> or download and run the scanner locally. I prefer this local method which utilizes the <a href="http://www.java.com/">java runtime</a>.</p>
<p>To use <strong>JSLint</strong> locally:</p>
<ol>
<li>Download and unzip <a href="http://www.mozilla.org/rhino/download.html">Rhino</a> to a folder on your computer. You need <em>js.jar</em></li>
<li>Download and save the JSLint library file <a href="http://www.jslint.com/rhino/jslint.js"><em>jslint.js</em></a></li>
<li>Run JSLint in the Rhino Shell passing it a JavaScript file to scan. Here is the command I use assuming <em>js.jar</em>, <em>jslint.js</em>, and <em>MYBIG.js</em> are all in the same directory.</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">java <span style="color: #660033;">-classpath</span> js.jar 
org.mozilla.javascript.tools.shell.Main 
jslint.js MYBIG.js</pre></div></div>

<p>You will then see a list of errors found by JSLint and suggestions for fixing your code. Some of the most common items are:</p>
<ul>
<li>Missing end of line semi-colon delimiters <font color="#800080">;</font><strong> </strong></li>
<li>Not using <em>dot notation</em> to reference DOM objects (ex. <font color="#800080">form['name'].input.value <font color="#000000">instead of</font> form.name.input.value</font> )</li>
<li>Using <font color="#800080">==</font> instead of <font color="#800080">===</font> for comparing with null, undefined, booleans, zero and &#8220;&#8221;</li>
<li>Variable scope issues caused by declaring variables inside of loops instead of declaring them first in functions definitions.</li>
<li>Not using curly braces in your conditional blocks. So make a point to always do <font color="#800080">If(x){doX();}else{doY();}</font> even if you have one liners.</li>
<li>Stay away from using <font color="#800080"><strike>eval()</strike></font> or <font color="#800080"><strike>with().</strike></font><font color="#000000"> eval is evil <img src='http://www.seifi.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </font></li>
<li>Create your arrays using literal notation <font color="#800080">[]</font> instead of <font color="#800080"><strike>new Array()</strike></font></li>
<li>Create your objects using <font color="#800080">{}</font> instead of <font color="#800080"><strike>new Object()</strike></font></li>
<li>Avoid using <font color="#800080"><strike>javascript:function()</strike></font> in URLs</li>
<li>You can read more suggestions in the JSLint <a href="http://www.jslint.com/lint.html">docs</a>.</li>
</ul>
<h3><strong>2) Join your files</strong></h3>
<p>If you have five separate CSS files and three different JavaScript files, your server has to answer 8 HTTP requests per client. Each request requires additional processing and slows down your page loading. By concatenating your CSS and JavaScript files to only 2, you should see page load time improvements, especially when client requests are coming from distant networks.</p>
<p>Another tip that I have seen is to move your JavaScript include tags to the very bottom of the page, right before the &lt;/body&gt; tag. This will allow the browser to draw the DOM before loading your library files and the page will appear to load faster.</p>
<p>So after your various source files are nice and lint free, and combined into a single library file you are ready to start shrinking.</p>
<h3><strong>3) Shrink your library</strong></h3>
<p>Before shipping your code, shrink it. JavaScript and CSS files are not compiled and they contain lots of wasted whitespace which are nice to have when you&#8217;re coding but serve no benefit to the user of your website. There are four different tools you can use to filter out the unnecessary bits from your JavaScript and CSS files, and for the most part they are doing the same thing. I personally use ShrinkSafe which is a happy safe medium. The reason is that this tool does not mangle your code so that its API will stay in tact. If you choose to use a decryption based method to obfuscate your code, it can have harmful side effects. First, the size of the encrypted file can in some cases actually be larger than the original! Second, your scripted API can get mangled, forcing you to update all external pointers to your code. If you have any clients who use your API via JavaScript, you should obviously take great caution in using encryption methods.</p>
<blockquote><p><u>Caution:</u> As always, backup your code before making changes to them using these tools! There is no undo!</p></blockquote>
<h4><strong>JavaScript Shrinking</strong></h4>
<ol>
<li><a href="http://javascript.crockford.com/jsmin.html">JSMin</a> removes extra white-space and comments. It also reduces the line count by increasing the maximum line width. The result a bit uglier and harder to read and debug but also a bit smaller. Unlike ShrinkSafe, though JSMin does not edit your function arguments. You can <a href="http://javascript.crockford.com/jsmin.html">download</a> it in a variety of flavors. Here is a DOS executable version and the command to run it.

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">jsmin <span style="color: #000000; font-weight: bold;">&lt;</span>big.jsb <span style="color: #000000; font-weight: bold;">&gt;</span>min_jsmin.js <span style="color: #ff0000;">&quot;(c)2007 CORP&quot;</span></pre></div></div>

</li>
<li><a href="http://alex.dojotoolkit.org/shrinksafe/">ShrinkSafe</a> removes extra white-space and comments, but keeps one statement per line which is easy on the eye if you decide to edit your shrunk file. It also shrinks function arguments by replacing them with consecutive _## values which tends to reduce the files size some more. Download the jar file <a href="http://svn.dojotoolkit.org/dojo/trunk/buildscripts/lib/custom_rhino.jar">here</a> and run it as follows:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">java <span style="color: #660033;">-jar</span> custom_rhino.jar <span style="color: #660033;">-c</span> big.js <span style="color: #000000; font-weight: bold;">&gt;</span> 
min_shrinksafe.js <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span></pre></div></div>

</li>
<li><a href="http://dean.edwards.name/packer/">Packer</a> has a few options you can choose to minify your scripts. The normal option removes extra white-space and puts the entire file in one super long line. You can also choose to shrink  function as well as encode your script using a base62 algorithm. You can <a target="_blank" href="http://dean.edwards.name/packer/">try it</a> online. Although your file size is considerably smaller, depending on the complexity and cleanliness of your code (see JSLint above) using the two options in Packer might introduce errors with your code. In my case I had no problems with them.</li>
<li><a href="http://hometown.aol.de/_ht_a/memtronic/">MemTronic</a> &#8211; Hardcore shrinkers out there can try this online tool which produces the smallest file size in my tests. Be warned that this is only for the braveheart coders, has some known issues and may have some side effects.</li>
</ol>
<p>I have run Prototype.js against these 4 tools and the results are shown below. The results show that you can save at least 20% on your file size without compromising much stability.</p>
<table border="0" width="90%" cellPadding="0" cellSpacing="1" class="gridtable">
<tr>
<th>Tool Used</th>
<th>File Name</th>
<th>File Size</th>
<th>Lines</th>
<th>Reduced</th>
</tr>
<tr>
<td>None</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/prototype.js">prototype.js</a></td>
<td>71,260</td>
<td>2514</td>
<td>Original</td>
</tr>
<tr>
<td>JSMin</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_jsmin.js">min_jsmin.js</a></td>
<td>54,035</td>
<td>183</td>
<td>-24%</td>
</tr>
<tr>
<td>Shrinksafe</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_shrinksafe.js">min_shrinksafe.js</a></td>
<td>50,725</td>
<td>1972</td>
<td>-29%</td>
</tr>
<tr>
<td>Packer</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_packer_noptions.js">min_packer_noptions.js</a></td>
<td>53,455</td>
<td>1</td>
<td>-25%</td>
</tr>
<tr>
<td>Packer</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_packer_shrunkvars.js">min_packer_shrunkvars.js</a></td>
<td>43,903</td>
<td>1</td>
<td>-38%</td>
</tr>
<tr>
<td>Packer</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_packer_encoded.js">min_packer_encoded.js</a></td>
<td>29,273</td>
<td>1</td>
<td>-59%</td>
</tr>
<tr>
<td>Packer</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_packer_both.js">min_packer_both.js</a></td>
<td>27,634</td>
<td>1</td>
<td>-61%</td>
</tr>
<tr>
<td>MemTronic</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_memtronic_compress.js">min_memtronic_compress.js</a></td>
<td>24,483</td>
<td>1</td>
<td>-66%</td>
</tr>
</table>
<h4><strong><strong>CSS Shrinking</strong></strong></h4>
<ol>
<li><a href="http://www.cleancss.com/">Clean CSS</a> &#8211; This tool creates the best results, reducing the files size while maintaining a nicely formatted and readable CSS file. It has a plethora of options to choose from as well. For example, you can sort the properties of all the selectors which is a godsend for neat-freaks like me. It will also compress your css by converting possible properties to use shorthand notations. You can choose to save your comments.</li>
<li><a href="http://www.cssoptimiser.com/">CSS Optimiser</a> &#8211; This tool only has one option which is to remove line breaks or not. Does a good job however the final file size does not decrease much if you don&#8217;t pick that option, which makes the css tough to read.</li>
<li><a href="http://iceyboard.no-ip.org/projects/css_compressor">Icey CSS Compressor</a> &#8211;  Here is another powerful tool with lots of options to go around. Here are a few of them: Convert colors to hex, combine identical rules, combine properties, combine selectors, remove useless padding and margin. It also outputs in a nice colorful format for you. However there is no option to keep line breaks in tact so you get the output all in one line, and in my case this actually created an error.</li>
<li><a href="http://flumpcakes.co.uk/css/optimiser/">Flumpcakes Optimiser</a> &#8211; This tool has a few useful options such as combining backgrounds, fonts, lists, borders, and style which appear in multiple places. It can also convert RGB to hex and absolute to relative.</li>
</ol>
<p>I ran the CSS from <a href="http://reader.earthlink.net/">EarthLink ReaDeR</a> through the top four tools and the results are shown below.</p>
<table border="0" width="90%" cellPadding="0" cellSpacing="1" class="gridtable">
<tr>
<th>Tool Used</th>
<th>File Name</th>
<th>File Size</th>
<th>Lines</th>
<th>Reduced</th>
</tr>
<tr>
<td>None</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/reader.css">reader.css</a></td>
<td>12,875</td>
<td>227</td>
<td>Original</td>
</tr>
<tr>
<td>Clean CSS</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_cleancss.css">min_cleancss.css</a></td>
<td>11,735</td>
<td>940</td>
<td>-2%</td>
</tr>
<tr>
<td>CSS Optimiser</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_cssoptimiser.css">min_cssoptimiser.css</a></td>
<td>11,304</td>
<td>2</td>
<td>-2%</td>
</tr>
<tr>
<td>Icey CSS Compressor</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_icey.css">min_icey.css</a></td>
<td>10,383</td>
<td>1</td>
<td>-3%</td>
</tr>
<tr>
<td>Flumpcakes Optimisor</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_flumpcakes.css">min_flumpcakes.css</a></td>
<td>12,885</td>
<td>796</td>
<td>0%</td>
</tr>
</table>
<p><!--adsense#post--></p>
<h3><strong>4) Compress your files</strong></h3>
<p>The HTTP implementation covers accept-encoding and content-encoding in detail and most browsers today support these methods. Basically when a browser sends a request, it tells the server it would like to have the file back in a compressed format such as gzip or deflate. The server then compresses the file and sends it back, and the browser decompresses the file and renders it in the browser. The most common format used today is GZip. Here is how to setup GZip in two popular web servers.</p>
<ol>
<li><strong>Apache &amp; mod_gzip</strong> &#8211; If you are running on Apache and have already compiled it with mod_gzip you can easily <a href="http://www.schroepl.net/projekte/mod_gzip/config.htm">configure</a> gzip compression by adding these lines to an .htaccess file placed in your web root or your http.conf file.

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mod_gzip_on Yes
mod_gzip_item_include <span style="color: #c20cb9; font-weight: bold;">file</span> \.php$
mod_gzip_item_include <span style="color: #c20cb9; font-weight: bold;">file</span> \.html$
mod_gzip_item_include mime ^text<span style="color: #000000; font-weight: bold;">/</span>html$
mod_gzip_item_include <span style="color: #c20cb9; font-weight: bold;">file</span> \.txt$
mod_gzip_item_include mime ^text<span style="color: #000000; font-weight: bold;">/</span>plain$
mod_gzip_item_include <span style="color: #c20cb9; font-weight: bold;">file</span> \.css$
mod_gzip_item_include mime ^text<span style="color: #000000; font-weight: bold;">/</span>css$
mod_gzip_item_include <span style="color: #c20cb9; font-weight: bold;">file</span> \.js$
mod_gzip_item_include mime ^application<span style="color: #000000; font-weight: bold;">/</span>x-javascript$
mod_gzip_item_exclude mime ^image<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>If you don&#8217;t have access to your .htaccess file but do have php compiled with the <a href="http://us2.php.net/manual/en/ref.zlib.php">zlib</a> module you can rename your javascript files to .php extensions and add this to the top of your file.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ob_gzhandler&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: text/javascript;charset:UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cache-Control: must-revalidate&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">60</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">60</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">24</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">365</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// one year</span>
<span style="color: #000088;">$ExpStr</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Expires: &quot;</span> <span style="color: #339933;">.</span>
<span style="color: #990000;">gmdate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;D, d M Y H:i:s&quot;</span><span style="color: #339933;">,</span>
<span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; GMT&quot;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ExpStr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</li>
<li><strong>JBoss and Tomcat</strong> &#8211; To enable compression in a J2EE environment running Tomcat within <a href="http://www.jboss.com/">JBoss</a>, you can now enable compression by editing your server.xml that sits in the tomcat.sar folder. Just add these attributes to the Connector node:

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connector</span> <span style="color: #000066;">port</span>=<span style="color: #ff0000;">&quot;8080&quot;</span> <span style="color: #000066;">compression</span>=<span style="color: #ff0000;">&quot;on&quot;</span> </span>
<span style="color: #009900;"><span style="color: #000066;">compressionMinSize</span>=<span style="color: #ff0000;">&quot;300&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">noCompressionUserAgents</span>=<span style="color: #ff0000;">&quot;gozilla, traviata&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">compressableMimeType</span>=<span style="color: #ff0000;">&quot;text/html,text/xml,text/css,</span>
<span style="color: #009900;">text/javascript, application/x-javascript,</span>
<span style="color: #009900;">application/javascript&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

</li>
</ol>
<h3><strong>The Results</strong></h3>
<p>Finally, here are two pages that use the compressed versions of prototype.js and reader.css, one <a href="http://seifi.org/wp-content/uploads/2007/04/gzipped/index.php">with gzip compression enabled</a>, and the other <a href="http://seifi.org/wp-content/uploads/2007/04/nogzip/index.php">without gzip compression</a> enabled. Using the Net tab in <a href="http://www.seifi.org/node/477">FireBug</a> we can easily see that the gzipped version of both the CSS and JavaScript files actually result in less network traffic and faster loads times.</p>
<p>We cut our total throughput by 44 KB or 70%! Also the total load time is cut by 521ms or 51%, basically reduced from 1 second to half a second. If we do some quick math, for a website that gets 1,000,000 unique visitors per day, this is a daily savings of 44GB of bandwidth, and a total of about 145 precious hours saved.</p>
<table border="0" width="90%" cellPadding="0" cellSpacing="1" class="gridtable">
<tr>
<th>Size in KB</th>
<th>CSS</th>
<th>JavaScript</th>
<th>Total</th>
</tr>
<tr>
<td>No Compression</td>
<td>12KB</td>
<td>51KB</td>
<td>63KB</td>
</tr>
<tr>
<td>Gzipped</td>
<td>4KB</td>
<td>15KB</td>
<td>19KB</td>
</tr>
<tr>
<td>Reduction</td>
<td>8KB 67%</td>
<td>36KB 71%</td>
<td>44KB 70%</td>
</tr>
<tr>
<td colSpan="3">Savings for 1 mil uniques/day</td>
<td>44 GB</td>
</tr>
<tr>
<td colSpan="4" style="padding: 0px"><a href="http://seifi.org/wp-content/uploads/2007/04/nogzip/index.php"><img border="0" width="392" src="http://seifi.org/wp-content/uploads/2007/04/nogzip.gif" height="116" /></a></td>
</tr>
</table>
<p>
<p>&nbsp;</p>
<table border="0" width="90%" cellPadding="0" cellSpacing="1" class="gridtable">
<tr>
<th>Time in Milliseconds</th>
<th>CSS</th>
<th>JavaScript</th>
<th>Total</th>
</tr>
<tr>
<td>No Compression</td>
<td>281ms</td>
<td>741ms</td>
<td>1022ms</td>
</tr>
<tr>
<td>Gzipped</td>
<td>110</td>
<td>391</td>
<td>501ms</td>
</tr>
<tr>
<td>Reduction</td>
<td>171ms 61%</td>
<td>350ms 47%</td>
<td>521ms 51%</td>
</tr>
<tr>
<td colSpan="3">Savings for 1 mil uniques/day</td>
<td>145 Hrs.</td>
</tr>
<tr>
<td colSpan="4" style="padding: 0px"><a href="http://seifi.org/wp-content/uploads/2007/04/gzipped/index.php"><img border="0" width="392" src="http://seifi.org/wp-content/uploads/2007/04/gzipped.gif" height="116" /></a></td>
</tr>
</table>
<p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seifi.org/css/how_to_boost_your_javascript_and_css_performance.html/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 2.007 seconds -->
