client-side templating

361 Views Asked by At

Its been a while since i am working with the AJAX and getting templates from server-side hence creating huge traffic.

Fetching same HTML on single page with only different data, sometimes i feel guilty that i can do better than that.

Then an idea clicked in my mind and i researched on client-side templating.

Only thing i found good enough (i thought so since i did not practiced it yet), was jQote2 http://aefxx.com/jquery-plugins/jqote2/.

I just want suggestion from gurus that is it worth? Is there another good alternative?

2

There are 2 best solutions below

2
On BEST ANSWER

Here's my favorite:

http://ejohn.org/blog/javascript-micro-templating/

It looks like this:

<script type="text/html" id="user_tmpl">
  <% for ( var i = 0; i < users.length; i++ ) { %>
    <li><a href="<%=users[i].url%>"><%=users[i].name%></a></li>
  <% } %>
</script>

Its author is John Resig, creator of jQuery. Hope this helps. Cheers

3
On

I've not used jQote but I have used jQuery Templates which I believe is the official templating solution although someone might correct me on that. I've only had the chance to use it in a few home projects but so far I really like it especially for rendering out static content like in my news ticker example.

You can take a look at it here jQuery Templates

Dave Ward has some nice blog posts and also Stephen Walther

I've done a few jsFiddle's that show some basic syntax