by turtle4 · 16y ago · 0 comments
var link = { url: 'http://news.ycombinator.com, title: 'Hacker News' , extraStuff: someBigObject };
With JS templating: <div id='template'><a href='${url}'>${title}</a></div>
$('#template').tmpl(link);
* Pros: if you have to generate 100 links, you only passed down the template div once. Also, if the extraStuff property is really large, there is no bandwidth spent on sending it up, since it runs on the page* Cons: if you generate 0 links, you still passed down the template div once. If you have this view defined also in a server side template, you have duplicated view logic (really annoying).
With server side templating:
$.load('url/to/template', link);
* Pros: If you generate 0 links, no extra data is sent or received. Also, your view logic is all in one place (on the server).* Cons: If you generate 100 links, there are 100 extra HTTP requests, and you have to deal with timeouts, loading indicators, etc.