Note that there are some explanatory texts on larger screens.

plurals
  1. POImprove jQuery template performance
    primarykey
    data
    text
    <p><strong>Update</strong></p> <p>Apparently, jQuery templates can be compiled and it helps performance for templates with <strong>if statements</strong> shown <a href="http://jsperf.com/complex-template-vs-concat/4" rel="noreferrer">here</a>.</p> <p>But as shown <a href="http://jsperf.com/jquery-template-table-performance/5" rel="noreferrer">here</a>, the precompiled jQuery templates doesn't do much for my case since my template contains no logic block.</p> <p>For those who are suggesting the use of another templating engine, ideally I would like to use just jQuery templates as everyone on the team knows just jQuery. There is also <a href="http://jsperf.com/dom-vs-innerhtml-based-templating/42" rel="noreferrer">this</a> test case that compares a few templating engine.</p> <hr> <p>Hi,</p> <p>Just today I was told that there are performance issues with using jQuery templates.</p> <p>To compare, I have used jQuery templates and the good old string append method to add rows to a table. The results can be seen <a href="http://jsperf.com/jquery-template-table-performance" rel="noreferrer">here</a>. Using jQuery templates is about 65% slower compare to string append method, Ouch!</p> <p>I am wondering what can be done to improve the performance of the jQuery template script.</p> <p>The full script can be viewed in the link provided. But the basic idea is as follows:</p> <p>Template:</p> <pre><code>&lt;script type="x-jquery-tmpl" id="tmplRow"&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="checkbox" value="${id}" /&gt;&lt;/td&gt; &lt;td&gt;${firstName} ${lastName}&lt;/td&gt; &lt;td class="edit"&gt; &lt;a&gt;Edit&lt;/a&gt; &lt;input style="display:none;" type="hidden" value="Blah" /&gt; &lt;input class="cancel" type="button" value="cancel" /&gt; &lt;/td&gt; &lt;td class="select"&gt; &lt;a&gt;Select&lt;/a&gt; &lt;select style="display:none;"&gt; &lt;option&gt;0&lt;/option&gt; &lt;option&gt;1&lt;/option&gt; &lt;option&gt;2&lt;/option&gt; &lt;option&gt;3&lt;/option&gt; &lt;option&gt;4&lt;/option&gt; &lt;option&gt;5&lt;/option&gt; &lt;option&gt;6&lt;/option&gt; &lt;option&gt;7&lt;/option&gt; &lt;option&gt;8&lt;/option&gt; &lt;option&gt;9&lt;/option&gt; &lt;option&gt;10&lt;/option&gt; &lt;/select&gt; &lt;input class="cancel" type="button" value="cancel" /&gt; &lt;/td&gt; &lt;td&gt;More string&lt;/td&gt; &lt;td&gt;More string&lt;/td&gt; &lt;td&gt;More string&lt;/td&gt; &lt;td&gt;More string&lt;/td&gt; &lt;td&gt;More string&lt;/td&gt; &lt;td&gt;More string&lt;/td&gt; &lt;/tr&gt; &lt;/script&gt; </code></pre> <p>Data:</p> <pre><code>&lt;script type="text/javascript"&gt; var data = []; for (var i = 0; i &lt; 100; i++) { var row = { id: i, firstName: 'john', lastName: 'doe' }; data.push(row); } &lt;/script&gt; </code></pre> <p>HTML:</p> <pre><code>&lt;table id="table"&gt;&lt;/table&gt; </code></pre> <p>Executes:</p> <pre><code>&lt;script type="text/javascript"&gt; $('#tmplRow').tmpl(data).appendTo('#table'); &lt;/script&gt; </code></pre> <p>Thanks,</p> <p>Chi</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload