<?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: Large selection lists and fast string concatenation in JavaScript</title>
	<atom:link href="http://help.dottoro.com/blog/large-selection-lists-and-fast-string-concatenation-in-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://help.dottoro.com/blog/large-selection-lists-and-fast-string-concatenation-in-javascript/</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Fri, 12 Aug 2011 07:52:48 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: frio80</title>
		<link>http://help.dottoro.com/blog/large-selection-lists-and-fast-string-concatenation-in-javascript/#comment-37</link>
		<dc:creator>frio80</dc:creator>
		<pubDate>Sat, 06 Feb 2010 02:36:26 +0000</pubDate>
		<guid isPermaLink="false">http://help.dottoro.com/blog/?p=24#comment-37</guid>
		<description>I did some work on this as well.  Here&#039;s some things I found:

1. This is very fast
var citySelect = document.getElementById(&#039;city_id&#039;),
		selectOption = null,
		ops = &quot;&quot;,
		c = [],
		docFrag = null;

	docFrag = document.createDocumentFragment();
	selectOption = document.createElement(&#039;option&#039;);
	
	for (var city in cities) {		
		ops = selectOption.cloneNode(&quot;false&quot;);
		ops.value = city;
		ops.text = cities[city];
		docFrag.appendChild(ops);
	};
	
	citySelect.appendChild(docFrag.cloneNode(&quot;true&quot;));

2.  Removing the element from the DOM and adding it back in is very fast (of course, you lose your attached events)
var citySelect = document.getElementById(&#039;city_id&#039;),
		c = document.getElementById(&#039;city&#039;),
		selectOption = null,
		ops = &quot;&quot;;
		
	selectBox = document.createElement(&quot;select&quot;);
	selectBox.id = &#039;city_id&#039;;
	selectBox.name = &#039;name_id&#039;;
	selectOption = document.createElement(&#039;option&#039;);
	
	for (var city in cities) {
		ops = selectOption.cloneNode(&quot;false&quot;);
		ops.value = city;
		ops.text = cities[city];
		selectBox.appendChild(ops);
	};
	
	c.removeChild(citySelect);
	c.appendChild(selectBox);

3.  This is extremely quick for clearing the select options array
	Array.prototype.splice.call(selectbox.options, 0);</description>
		<content:encoded><![CDATA[<p>I did some work on this as well.  Here's some things I found:</p>
<p>1. This is very fast<br />
var citySelect = document.getElementById('city_id'),<br />
		selectOption = null,<br />
		ops = "",<br />
		c = [],<br />
		docFrag = null;</p>
<p>	docFrag = document.createDocumentFragment();<br />
	selectOption = document.createElement('option');</p>
<p>	for (var city in cities) {<br />
		ops = selectOption.cloneNode("false");<br />
		ops.value = city;<br />
		ops.text = cities[city];<br />
		docFrag.appendChild(ops);<br />
	};</p>
<p>	citySelect.appendChild(docFrag.cloneNode("true"));</p>
<p>2.  Removing the element from the DOM and adding it back in is very fast (of course, you lose your attached events)<br />
var citySelect = document.getElementById('city_id'),<br />
		c = document.getElementById('city'),<br />
		selectOption = null,<br />
		ops = "";</p>
<p>	selectBox = document.createElement("select");<br />
	selectBox.id = 'city_id';<br />
	selectBox.name = 'name_id';<br />
	selectOption = document.createElement('option');</p>
<p>	for (var city in cities) {<br />
		ops = selectOption.cloneNode("false");<br />
		ops.value = city;<br />
		ops.text = cities[city];<br />
		selectBox.appendChild(ops);<br />
	};</p>
<p>	c.removeChild(citySelect);<br />
	c.appendChild(selectBox);</p>
<p>3.  This is extremely quick for clearing the select options array<br />
	Array.prototype.splice.call(selectbox.options, 0);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: uberVU - social comments</title>
		<link>http://help.dottoro.com/blog/large-selection-lists-and-fast-string-concatenation-in-javascript/#comment-36</link>
		<dc:creator>uberVU - social comments</dc:creator>
		<pubDate>Thu, 04 Feb 2010 21:50:30 +0000</pubDate>
		<guid isPermaLink="false">http://help.dottoro.com/blog/?p=24#comment-36</guid>
		<description>&lt;strong&gt;Social comments and analytics for this post...&lt;/strong&gt;

This post was mentioned on Reddit by maritz: Creating an array and then joining this array is faster than just concatenating the string? That is fucked up.

But very good to know. Thanks.
I&#039;ll have to test this on Node, to see if it&#039;s the same the...</description>
		<content:encoded><![CDATA[<p><strong>Social comments and analytics for this post...</strong></p>
<p>This post was mentioned on Reddit by maritz: Creating an array and then joining this array is faster than just concatenating the string? That is fucked up.</p>
<p>But very good to know. Thanks.<br />
I'll have to test this on Node, to see if it's the same the...</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: derek</title>
		<link>http://help.dottoro.com/blog/large-selection-lists-and-fast-string-concatenation-in-javascript/#comment-35</link>
		<dc:creator>derek</dc:creator>
		<pubDate>Thu, 04 Feb 2010 16:19:26 +0000</pubDate>
		<guid isPermaLink="false">http://help.dottoro.com/blog/?p=24#comment-35</guid>
		<description>Encouraging that IE8 seems to have fixed some of this.</description>
		<content:encoded><![CDATA[<p>Encouraging that IE8 seems to have fixed some of this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Justin</title>
		<link>http://help.dottoro.com/blog/large-selection-lists-and-fast-string-concatenation-in-javascript/#comment-34</link>
		<dc:creator>Justin</dc:creator>
		<pubDate>Thu, 04 Feb 2010 01:54:22 +0000</pubDate>
		<guid isPermaLink="false">http://help.dottoro.com/blog/?p=24#comment-34</guid>
		<description>Well that mangled my comment, should have been:

&lt;code&gt;
var selectArr = new Array();
for (var i = 0; i &lt; 8000; i++) {
    selectArr.push(i);
}
container.innerHTML +=
    &quot;&lt;select&gt;&amp;ltoption&gt;&quot; +
    selectArr.join(&quot;&lt;/option&gt;&amp;ltoption&gt;&quot;) +
    &quot;&lt;/select&gt;&amp;lt/option&gt;&quot;;
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Well that mangled my comment, should have been:</p>
<p><code><br />
var selectArr = new Array();<br />
for (var i = 0; i &lt; 8000; i++) {<br />
    selectArr.push(i);<br />
}<br />
container.innerHTML +=<br />
    &quot;&lt;select&gt;&amp;ltoption&gt;&quot; +<br />
    selectArr.join(&quot;&lt;/option&gt;&amp;ltoption&gt;&quot;) +<br />
    &quot;&lt;/select&gt;&amp;lt/option&gt;&quot;;<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Justin</title>
		<link>http://help.dottoro.com/blog/large-selection-lists-and-fast-string-concatenation-in-javascript/#comment-33</link>
		<dc:creator>Justin</dc:creator>
		<pubDate>Thu, 04 Feb 2010 01:52:04 +0000</pubDate>
		<guid isPermaLink="false">http://help.dottoro.com/blog/?p=24#comment-33</guid>
		<description>You can reduce the number of concatinations further with:

    var selectArr = new Array();
    for (var i = 0; i &lt; 8000; i++) {
        selectArr.push(i);
    }
    container.innerHTML +=
        &quot;&quot; +
        selectArr.join(&quot;&quot;) +
        &quot;&quot;;</description>
		<content:encoded><![CDATA[<p>You can reduce the number of concatinations further with:</p>
<p>    var selectArr = new Array();<br />
    for (var i = 0; i &lt; 8000; i++) {<br />
        selectArr.push(i);<br />
    }<br />
    container.innerHTML +=<br />
        &quot;" +<br />
        selectArr.join("") +<br />
        "";</p>
]]></content:encoded>
	</item>
</channel>
</rss>

