<?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>Andy Girvan &#187; optimization - Andy Girvan - Freelance Web &amp; Mobile Developer, London - HTML5/JS/CSS3 -  PHP/MySQL - iOS</title>
	<atom:link href="http://andygirvan.com/tag/optimization/feed/" rel="self" type="application/rss+xml" />
	<link>http://andygirvan.com</link>
	<description>Freelance Web &#38; Mobile Developer, London - HTML5/JS/CSS3 -  PHP/MySQL - iOS</description>
	<lastBuildDate>Tue, 17 Apr 2012 19:16:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>5 jQuery optimization tips from jsPerf</title>
		<link>http://andygirvan.com/2012/04/5-jquery-optimization-tips-from-jsperf/</link>
		<comments>http://andygirvan.com/2012/04/5-jquery-optimization-tips-from-jsperf/#comments</comments>
		<pubDate>Wed, 04 Apr 2012 13:19:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery tips]]></category>
		<category><![CDATA[jsperf]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://andygirvan.com/?p=1141</guid>
		<description><![CDATA[jQuery is a wonderful library that offers a massive amount of functionality in a nicely wrapped up package. But jQuery is quite bloated, with the minified version weighing in at 94kb. If you&#8217;re micro-optimizing, any of these little tips should help to squeeze out the hidden milliseconds on load/run time. Lucikly there is a website [...]]]></description>
			<content:encoded><![CDATA[<p>jQuery is a wonderful library that offers a massive amount of functionality in a nicely wrapped up package. But jQuery is quite bloated, with the minified version weighing in at 94kb. If you&#8217;re micro-optimizing, any of these little tips should help to squeeze out the hidden milliseconds on load/run time.</p>
<p>Lucikly there is a website called <a href="http://jsperf.com" target="_blank">jsperf.com</a> which allows you to test &#038; compare different blocks of code against each other, and see the results of each &#8211; recording how fast each block ran in which browser. Here are some simple but handy tips.</p>
<p><span id="more-1141"></span></p>
<h4>Document Ready</h4>
<p><a href="http://jsperf.com/ready/2" target="_blank">http://jsperf.com/ready/2</a></p>
<p>When calling for jQuery to fire when the whole page has loaded &#8211; aka on document ready &#8211; there are a few options available to initiate this. The test shows that the quickest, by quite a way is:</p>
<p><script type="text/javascript" src="https://gist.github.com/2300208.js?file=gistfile1.txt"></script><br />
<br /></p>
<h4>A better .each() loop</h4>
<p><a href="http://jsperf.com/jquery-each-vs-quickeach" target="_blank">http://jsperf.com/jquery-each-vs-quickeach</a></p>
<p>Looping through X amount of the same element can be quite time intensive, especially if you&#8217;re doing manipulation in each loop. The built in .each method does a decent job, but James Padolsey at jsperf has taken advantage of object caching to create a faster loop extension, called .quickEach:</p>
<p><script src="https://gist.github.com/2300218.js?file=gistfile1.txt"></script><br />
<br /></p>
<h4>CSS3 Selector vs Jquery</h4>
<p><a href="http://jsperf.com/jquery-css3-not-vs-not" target="_blank">http://jsperf.com/jquery-css3-not-vs-not</a></p>
<p>Ok, so this is a test for the latest browsers (which you should be on anyway) but this test shows that using a CSS3 selector to help jQuery navigate the code is quicker than relying on the library itself.</p>
<p><script src="https://gist.github.com/2300976.js?file=gistfile1.txt"></script><br />
<br /></p>
<h4>Switch vs If/Else</h4>
<p><a href="http://jsperf.com/switch-if-else" target="_blank">http://jsperf.com/switch-if-else</a></p>
<p>Quite an interesting one, this. It seems that an if/else conditional block is faster, in all browsers, than a switch/case block &#8211; remember this if you&#8217;ve got a switch/case block in a loop.<br />
<br /></p>
<h4>jQuery selector vs normal javascript</h4>
<p><a href="http://jsperf.com/getelementbyid-vs-jquery-id/5">http://jsperf.com/getelementbyid-vs-jquery-id/5</a></p>
<p>This is a bit obvious this one, but one that is often forgotten. This test proves that, if you can, using standard javascript is always preferable if you&#8217;re optimizing as it doesn&#8217;t require the loading of a large library before firing. Although jQuery is very useful for pretty much all web JS development, there is absolutely no excuse for using jQuery to just select a canvas element.</p>
<p><script src="https://gist.github.com/2301013.js?file=gistfile1.txt"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://andygirvan.com/2012/04/5-jquery-optimization-tips-from-jsperf/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

