问题
I am developing a large scale application highly dependent on javascript. Part of this will be displying information on screen. I am looking to display information on the ui and I am looking at using javascript templating to do such. I will be using the jquery framework.
Any suggestions or recommendations to javascript/jquery templating frameworks?
回答1:
It's not jQuery based, but according to performance tests on jsperf.com, the doT.js templating framework is consistently the fastest JS templating framework. It has no dependencies, so you should be able to use it alongside jQuery.
回答2:
Here is a useful library for jquery templating: http://icanhazjs.com/ Plus, it's got a fun name!
回答3:
Only agree with GregL partially. The original test does not consider the time spent to eventually append the rendered html to the page.
You should also check out http://jsperf.com/dom-vs-innerhtml-based-templating/259
This test will include appending the rendered html text to the page.
You can compare it with http://jsperf.com/dom-vs-innerhtml-based-templating/257
The original test case. You will find out that the difference across template engines is not that significant. You do need to consider more about the usability of a template engine, unless you are going to simply render a chuck of html text without put it to the client browser.
Besides, in my opinion, a good template engine should greatly help you maintain the templates, help you write less to do more which is also the principle of jQuery.
doT.js is really great in performance, but I don't agree that it could help you code efficiently.
I am now working on an open source project to try to build a easy-to-use template engine. It can help you manage your templates in a tree-like structure, create template reference, define your own syntax, bind data to html dom.. please give it a try
http://jspopisno1.github.com/Beard
You can also have a read another question in stackoverflow
https://stackoverflow.com/questions/552934/what-javascript-templating-engine-do-you-recommend/8129492#8129492
回答4:
Yes, i've used this John Resig’s Microtemplating engine with great success in several projects. It's very simple, maintainable, and easy to use.
来源:https://stackoverflow.com/questions/8129847/javascript-jquery-templating-suggestions