<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
	
	>
<channel>
	<title>Comments on: Speed Up the jQuery Code: Selectors&#8217; Cache</title>
	<atom:link href="/2010/06/19/speed-up-the-jquery-code-selectors-cache/feed/" rel="self" type="application/rss+xml" />
	<link>/2010/06/19/speed-up-the-jquery-code-selectors-cache/</link>
	<description>on web development</description>
	<lastBuildDate>Fri, 26 Oct 2018 21:40:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>By: Greg</title>
		<link>/2010/06/19/speed-up-the-jquery-code-selectors-cache/comment-page-1/#comment-13181</link>
		<dc:creator><![CDATA[Greg]]></dc:creator>
		<pubDate>Fri, 25 Jun 2010 05:44:12 +0000</pubDate>
		<guid isPermaLink="false">/?p=1630#comment-13181</guid>
		<description><![CDATA[@Dan Beam  - I don&#039;t care about it faster or not, but for tip &quot;console.log&quot; very big Thanks]]></description>
		<content:encoded><![CDATA[<p>@Dan Beam  &#8211; I don&#8217;t care about it faster or not, but for tip &#8220;console.log&#8221; very big Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stoimen</title>
		<link>/2010/06/19/speed-up-the-jquery-code-selectors-cache/comment-page-1/#comment-13178</link>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
		<pubDate>Thu, 24 Jun 2010 07:10:12 +0000</pubDate>
		<guid isPermaLink="false">/?p=1630#comment-13178</guid>
		<description><![CDATA[@Dan Beam - I know I&#039;m accessing the DOM of course, and I know also this is a slow operation. While there are different techniques of optimizing, here I think the test is correct just because it&#039;s using the same DOM access methods. Thus I suppose only the selector is changing the performance results!

greetings,
stoimen]]></description>
		<content:encoded><![CDATA[<p>@Dan Beam &#8211; I know I&#8217;m accessing the DOM of course, and I know also this is a slow operation. While there are different techniques of optimizing, here I think the test is correct just because it&#8217;s using the same DOM access methods. Thus I suppose only the selector is changing the performance results!</p>
<p>greetings,<br />
stoimen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Beam</title>
		<link>/2010/06/19/speed-up-the-jquery-code-selectors-cache/comment-page-1/#comment-13177</link>
		<dc:creator><![CDATA[Dan Beam]]></dc:creator>
		<pubDate>Wed, 23 Jun 2010 21:02:22 +0000</pubDate>
		<guid isPermaLink="false">/?p=1630#comment-13177</guid>
		<description><![CDATA[@haliphax - You&#039;re missing the point - it&#039;s about client-side performance.  if you want to change alot of UI stuff or update many different parts of the DOM tree you&#039;ll have to find a way to reference those Nodes (through a selection engine or DOM methods).  You don&#039;t want your website to suck or be stuck in the 90s, do you?

I don&#039;t think that your test is stressing the right area.  I thought from the title it&#039;d be simply reading / selecting / parsing the DOM, but you&#039;re also setting the innerHTML of an element as well (which requires it to re-parse that text and create a DOM Node tree).

It seems like a test truer to this title (simply caching selectors) would be something like this:
&lt;pre lang=&quot;javascript&quot;&gt;
    // Without caching

    $([1,2,3,4,5]).each(function () {
        for (var i = 0, start = +new Date; i &lt; 100000; ++i) {
            $(&#039;#sponsors&#039;).attr(&#039;class&#039;);
        }
        console.log(+new Date - start);
    });

    // With caching

    $([1,2,3,4,5]).each(function () {
        for (var i = 0, $sponsors = $(&#039;#sponsors&#039;), start = +new Date; i &lt; 100000; ++i) {
            $sponsors.attr(&#039;class&#039;);
        }
        console.log(+new Date - start);
    });
&lt;/pre&gt;
Which yielded the results (on a site I used to work on, http://lalive.com)/
&lt;pre&gt;
921
917
902
902
903
260
259
261
262
261
&lt;/pre&gt;
So, here we see a more pronounced difference.]]></description>
		<content:encoded><![CDATA[<p>@haliphax &#8211; You&#8217;re missing the point &#8211; it&#8217;s about client-side performance.  if you want to change alot of UI stuff or update many different parts of the DOM tree you&#8217;ll have to find a way to reference those Nodes (through a selection engine or DOM methods).  You don&#8217;t want your website to suck or be stuck in the 90s, do you?</p>
<p>I don&#8217;t think that your test is stressing the right area.  I thought from the title it&#8217;d be simply reading / selecting / parsing the DOM, but you&#8217;re also setting the innerHTML of an element as well (which requires it to re-parse that text and create a DOM Node tree).</p>
<p>It seems like a test truer to this title (simply caching selectors) would be something like this:</p>
<pre lang="javascript">
    // Without caching

    $([1,2,3,4,5]).each(function () {
        for (var i = 0, start = +new Date; i < 100000; ++i) {
            $('#sponsors').attr('class');
        }
        console.log(+new Date - start);
    });

    // With caching

    $([1,2,3,4,5]).each(function () {
        for (var i = 0, $sponsors = $('#sponsors'), start = +new Date; i < 100000; ++i) {
            $sponsors.attr('class');
        }
        console.log(+new Date - start);
    });
</pre>
<p>Which yielded the results (on a site I used to work on, <a href="http://lalive.com/" rel="nofollow">http://lalive.com/</a>)</p>
<pre>
921
917
902
902
903
260
259
261
262
261
</pre>
<p>So, here we see a more pronounced difference.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: haliphax</title>
		<link>/2010/06/19/speed-up-the-jquery-code-selectors-cache/comment-page-1/#comment-13176</link>
		<dc:creator><![CDATA[haliphax]]></dc:creator>
		<pubDate>Wed, 23 Jun 2010 14:16:09 +0000</pubDate>
		<guid isPermaLink="false">/?p=1630#comment-13176</guid>
		<description><![CDATA[@Teppo: It&#039;s Javascript. Does the number of users visiting the site even come into play here? It&#039;s not as if you&#039;re saving bandwidth or server CPU cycles with a &quot;cached&quot; query vs. an &quot;ad-hoc&quot; query in this circumstance... all of the code is executed on the client&#039;s machine--not on the server.]]></description>
		<content:encoded><![CDATA[<p>@Teppo: It&#8217;s Javascript. Does the number of users visiting the site even come into play here? It&#8217;s not as if you&#8217;re saving bandwidth or server CPU cycles with a &#8220;cached&#8221; query vs. an &#8220;ad-hoc&#8221; query in this circumstance&#8230; all of the code is executed on the client&#8217;s machine&#8211;not on the server.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Teppo</title>
		<link>/2010/06/19/speed-up-the-jquery-code-selectors-cache/comment-page-1/#comment-13164</link>
		<dc:creator><![CDATA[Teppo]]></dc:creator>
		<pubDate>Mon, 21 Jun 2010 08:25:53 +0000</pubDate>
		<guid isPermaLink="false">/?p=1630#comment-13164</guid>
		<description><![CDATA[&quot;Little&quot; things like this become _very_ important when you&#039;re developing complicated sites used by hundreds or thousands or even more people on daily basis. That&#039;s when &quot;just a few milliseconds&quot; really start making difference :-)]]></description>
		<content:encoded><![CDATA[<p>&#8220;Little&#8221; things like this become _very_ important when you&#8217;re developing complicated sites used by hundreds or thousands or even more people on daily basis. That&#8217;s when &#8220;just a few milliseconds&#8221; really start making difference 🙂</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stoimen</title>
		<link>/2010/06/19/speed-up-the-jquery-code-selectors-cache/comment-page-1/#comment-13159</link>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
		<pubDate>Sun, 20 Jun 2010 19:21:12 +0000</pubDate>
		<guid isPermaLink="false">/?p=1630#comment-13159</guid>
		<description><![CDATA[Agree! That&#039;s why I&#039;ve to make some tests with that, perhaps the difference will be more obvious.]]></description>
		<content:encoded><![CDATA[<p>Agree! That&#8217;s why I&#8217;ve to make some tests with that, perhaps the difference will be more obvious.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rich</title>
		<link>/2010/06/19/speed-up-the-jquery-code-selectors-cache/comment-page-1/#comment-13158</link>
		<dc:creator><![CDATA[Rich]]></dc:creator>
		<pubDate>Sun, 20 Jun 2010 19:16:29 +0000</pubDate>
		<guid isPermaLink="false">/?p=1630#comment-13158</guid>
		<description><![CDATA[The difference that you saw was probably so small because your DOM was so small and simple.

If you try this with some &quot;real world&quot; html, where the DOM is larger, and the selectors are more complex, you&#039;ll probably see a much greater difference.]]></description>
		<content:encoded><![CDATA[<p>The difference that you saw was probably so small because your DOM was so small and simple.</p>
<p>If you try this with some &#8220;real world&#8221; html, where the DOM is larger, and the selectors are more complex, you&#8217;ll probably see a much greater difference.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
