<?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>jQuery Tutorials &#38; Plugins &#187; jQuery Optimization</title>
	<atom:link href="http://jqueryblog.net/cat/jquery-optimization/feed/" rel="self" type="application/rss+xml" />
	<link>http://jqueryblog.net</link>
	<description></description>
	<lastBuildDate>Mon, 05 Jul 2010 08:45:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>jQuery Optimization : Avoid Unnecessary Selector</title>
		<link>http://jqueryblog.net/2009/11/jquery-optimization-avoid-unnecessary-selector/</link>
		<comments>http://jqueryblog.net/2009/11/jquery-optimization-avoid-unnecessary-selector/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 15:38:35 +0000</pubDate>
		<dc:creator>Osman Erdo&#287;an</dc:creator>
				<category><![CDATA[jQuery Optimization]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Selector]]></category>
		<category><![CDATA[subexpression]]></category>
		<category><![CDATA[Unnecessary Selector]]></category>

		<guid isPermaLink="false">http://jqueryblog.net/?p=29</guid>
		<description><![CDATA[Common subexpression elimination is a common way to optimize any programming code. Doing unnecessary selector is expensive. Doing something like this:
jQuery('.class').each(function(){
	jQuery(this).html();
	jQuery(this).find('div').each(function(){
		//etc.
	});
});
which required many selector it is best to use 1 instead since we are repeating ourselves and doing some redundant selector.
jQuery('.class').each(function(){
	var obj = jQuery(this);
	obj.html();
	obj.find('div').each(function(){
		//etc.
	});
});
This is something that we often see in many plugin. Many plugin [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjqueryblog.net%2F2009%2F11%2Fjquery-optimization-avoid-unnecessary-selector%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fjqueryblog.net%2F2009%2F11%2Fjquery-optimization-avoid-unnecessary-selector%2F" height="61" width="51" /></a></div><p>Common subexpression elimination is a common way to optimize any programming code. Doing unnecessary selector is expensive. Doing something like this:</p>
<pre class="brush: jscript;">jQuery('.class').each(function(){
	jQuery(this).html();
	jQuery(this).find('div').each(function(){
		//etc.
	});
});</pre>
<p>which required many selector it is best to use 1 instead since we are repeating ourselves and doing some redundant selector.</p>
<pre class="brush: jscript;">jQuery('.class').each(function(){
	var obj = jQuery(this);
	obj.html();
	obj.find('div').each(function(){
		//etc.
	});
});</pre>
<p>This is something that we often see in many plugin. Many plugin contains unnecessary selector which degrade the perform of the plugin little by little.</p>
]]></content:encoded>
			<wfw:commentRss>http://jqueryblog.net/2009/11/jquery-optimization-avoid-unnecessary-selector/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Optimization : Balance between JavaScript and jQuery</title>
		<link>http://jqueryblog.net/2009/11/jquery-optimization-balance-between-javascript-and-jquery/</link>
		<comments>http://jqueryblog.net/2009/11/jquery-optimization-balance-between-javascript-and-jquery/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 08:23:47 +0000</pubDate>
		<dc:creator>Osman Erdo&#287;an</dc:creator>
				<category><![CDATA[jQuery Optimization]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Optimization]]></category>

		<guid isPermaLink="false">http://jqueryblog.net/?p=20</guid>
		<description><![CDATA[jQuery is excellent to speed up ANY front-end developer job. However, there are times when jQuery may take more time to perform certain action than using JavaScript. For example,
css: function( key, value ) {
	// ignore negative width and height values
	if ( (key == 'width' &#124;&#124; key == 'height') &#38;&#38; parseFloat(value) &#60; 0 )
		value = undefined;
	return [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjqueryblog.net%2F2009%2F11%2Fjquery-optimization-balance-between-javascript-and-jquery%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fjqueryblog.net%2F2009%2F11%2Fjquery-optimization-balance-between-javascript-and-jquery%2F" height="61" width="51" /></a></div><p>jQuery is excellent to speed up ANY front-end developer job. However, there are times when jQuery may take more time to perform certain action than using JavaScript. For example,</p>
<pre class="brush: jscript;">css: function( key, value ) {
	// ignore negative width and height values
	if ( (key == 'width' || key == 'height') &amp;&amp; parseFloat(value) &lt; 0 )
		value = undefined;
	return this.attr( key, value, &quot;curCSS&quot; );
}</pre>
<p>The above is a CSS method in jQuery that takes a key and a value which we are familiar using in this way</p>
<pre class="brush: jscript;">jQuery('#id').css('display', 'block');</pre>
<p>We can see that jQuery present certain overhead for doing something simple where JavaScript can also achieve.</p>
<pre class="brush: jscript;">document.getElementById('id').style.display = 'block';</pre>
<p>Other methods such as show(), hide(), hasClass() and etc. also present some overhead which you should balance between complexity and efficiency. Hence, we must understand some of the cost of jQuery action and balance between JavaScript and jQuery. jQuery is build for general public and making a general public framework might means additional operation to meet everyone needs. Hence, if you truly going all out on optimization, you should consider the trade-off of some action between JavaScript and jQuery.</p>
]]></content:encoded>
			<wfw:commentRss>http://jqueryblog.net/2009/11/jquery-optimization-balance-between-javascript-and-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Optimization : Avoid Unnecessary Styling</title>
		<link>http://jqueryblog.net/2009/11/jquery-optimization-avoid-unnecessary-styling/</link>
		<comments>http://jqueryblog.net/2009/11/jquery-optimization-avoid-unnecessary-styling/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 17:43:21 +0000</pubDate>
		<dc:creator>Osman Erdo&#287;an</dc:creator>
				<category><![CDATA[jQuery Optimization]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Styling]]></category>

		<guid isPermaLink="false">http://jqueryblog.net/?p=18</guid>
		<description><![CDATA[This is another common mistake that many jQuery developer made. jQuery provides us with the ability to manipulate styling through styling methods. Although it is very convenient to do that but it also contribute to the size of the script and makes maintenance difficult. Furthermore, some of the selector is made solely for styling purposes [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjqueryblog.net%2F2009%2F11%2Fjquery-optimization-avoid-unnecessary-styling%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fjqueryblog.net%2F2009%2F11%2Fjquery-optimization-avoid-unnecessary-styling%2F" height="61" width="51" /></a></div><p>This is another common mistake that many jQuery developer made. jQuery provides us with the ability to manipulate styling through styling methods. Although it is very convenient to do that but it also contribute to the size of the script and makes maintenance difficult. Furthermore, some of the selector is made solely for styling purposes which makes it even undesirable. To make thing worst, the styles made with jQuery are all inline style which doesn’t help caching. Hence, instead of styling everything with jQuery. It is much more advisable to give classes to your tag and style it on a external stylesheet. Instead of writing jQuery styling such as these,</p>
<pre class="brush: jscript;">jQuery('div').each(function(){
	var obj = jQuery(this);
	obj.css({'background-color' : 'yellow', 'font-weight' : 'bolder', 'color': '#000', 'font-size': '15px'})
});</pre>
<p>Where styling is being applied through jQuery, we can just add a class or even better do it on the HTML file itself!</p>
<pre class="brush: jscript;">jQuery('div').each(function(){
	var obj = jQuery(this);
	obj.addClass(&quot;mystyling&quot;);
});</pre>
<p>This way we can easily eliminate a lot of extra code in our script. Unless, absolutely necessary to manipulate styling through jQuery, it is better to leave styling to the stylesheet.</p>
]]></content:encoded>
			<wfw:commentRss>http://jqueryblog.net/2009/11/jquery-optimization-avoid-unnecessary-styling/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery Optimization : Optimize Selector</title>
		<link>http://jqueryblog.net/2009/11/jquery-optimization-optimize-selector/</link>
		<comments>http://jqueryblog.net/2009/11/jquery-optimization-optimize-selector/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 10:39:19 +0000</pubDate>
		<dc:creator>Osman Erdo&#287;an</dc:creator>
				<category><![CDATA[jQuery Optimization]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Optimize Selector]]></category>
		<category><![CDATA[Selector]]></category>

		<guid isPermaLink="false">http://jqueryblog.net/?p=10</guid>
		<description><![CDATA[We can also optimize our selector other than being a bit specific on our selector. The key to optimize our selector is simple. Naive JavaScript provides two method to get id and tag (getElementById and getElementByTagName). Hence, it is always faster to use tag or id on your selector. No matter what algorithm used for [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjqueryblog.net%2F2009%2F11%2Fjquery-optimization-optimize-selector%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fjqueryblog.net%2F2009%2F11%2Fjquery-optimization-optimize-selector%2F" height="61" width="51" /></a></div><p>We can also optimize our selector other than being a bit specific on our selector. The key to optimize our selector is simple. Naive JavaScript provides two method to get id and tag (getElementById and getElementByTagName). Hence, it is always faster to use tag or id on your selector. No matter what algorithm used for classes and attributes selection, the naive built-in JavaScript method will always have the upper hand. Nonetheless, classes and attribute selector have also been improved dramatically through the introduction of ’sizzling’ selector engine. However, it is always advisable to reduce the number of attribute selector as they are the slowest in many cases. On the other hand, making your selector as simple as possible is good for pure tag and id selector but may not be true for attribute and selector.</p>
<pre class="brush: jscript;">jQuery('div')
jQuery('#id')
jQuery('.classes')
jQuery('p:last')</pre>
<p>is considered as good selectors while the below might not give you very good selector result.</p>
<pre class="brush: jscript;">jQuery('body div div')
jQuery('div#id')
jQuery('#id div.classes')
jQuery('.classes p:last')</pre>
<p>It is important to treat jQuery as a helper of JavaScript instead of a new language.</p>
]]></content:encoded>
			<wfw:commentRss>http://jqueryblog.net/2009/11/jquery-optimization-optimize-selector/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
