您推荐哪些 Javascript 模板引擎?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7788611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What Javascript Template Engines you recommend?
提问by kaha
I would like to know your opinion about javascript template engine, which one you think is better in terms of performance?
我想知道您对javascript模板引擎的看法,您认为在性能方面哪个更好?
I found some links where people do benchmarking:
我找到了一些人们进行基准测试的链接:
http://jsperf.com/jquery-template-table-performance/15
http://jsperf.com/jquery-template-table-performance/15
http://jsperf.com/jquery-template-table-performance/8
http://jsperf.com/jquery-template-table-performance/8
http://www.viget.com/extend/benchmarking-javascript-templating-libraries/
http://www.viget.com/extend/benchmarking-javascript-templating-libraries/
回答by CD..
Template-Engine-Chooser!- Tool to help select the right template engine for a project.
模板引擎选择器!- 帮助为项目选择正确模板引擎的工具。
回答by Daff
In terms of performance I found that it is not the templating engine itself but more if there is the possibility to precompile the templates. It is a good practice to concatenate and minify all your JavaScript source files into one file for production mode anyway, so it is basically the same step to precompile the templates, too.
在性能方面,我发现它不是模板引擎本身,而是更多,如果有可能预编译模板。无论如何,将所有 JavaScript 源文件连接并缩小到一个文件以用于生产模式是一种很好的做法,因此预编译模板也基本上是相同的步骤。
I've used jQuery template and Mustache for client side templating, but my favorite is still EJSwhich always peformed a lot faster than anything else I tried so far, especially in production mode (compiles to native string concatenation whenever possible and needs only one DOM access to actually insert the rendered view). It is part of the JavaScriptMVCframework and when using it with StealJSas the dependency manager it does all the template compiling into production for you already (the View Enginealso supports Micro, Mustache and jQuery template).
我已经将 jQuery 模板和 Mustache 用于客户端模板,但我最喜欢的仍然是EJS,它的执行速度总是比我迄今为止尝试过的任何其他方法都要快得多,尤其是在生产模式下(尽可能编译为本地字符串连接,并且只需要一个 DOM访问实际插入渲染视图)。它是JavaScriptMVC框架的一部分,当它与StealJS作为依赖管理器一起使用时,它已经为您完成所有模板编译到生产中(视图引擎还支持 Micro、Mustache 和 jQuery 模板)。
回答by Vladimir Starkov
May be PURE— it allows to transform JSON into HTML with templates made from your existed html, not from separate templatewith special syntax.
可能是纯的——它允许将 JSON 转换为 HTML,模板是由您现有的 html 制作的,而不是来自具有特殊语法的单独模板。
From the PURE's site:
来自 PURE 的网站:
Simple and ultra-fast templating tool to generate HTML from JSON data
The representation (HTML) and the logic (JS) remain totally separated
Works standalone or with dojo, DomAssistant, Ext JS, jQuery, Mootools, Prototype, Sizzle and Sly
从 JSON 数据生成 HTML 的简单且超快速的模板工具
表示 (HTML) 和逻辑 (JS) 保持完全分离
独立工作或与 dojo、DomAssistant、Ext JS、jQuery、Mootools、Prototype、Sizzle 和 Sly 一起工作
The best way to understand is to see what this library actually do: (from official demo)
最好的理解方法是看看这个库实际上做了什么:(来自官方演示)
All the demos are here
所有演示都在这里
回答by pixel 67
LinkedIn went with dust.js http://akdubya.github.com/dustjs/
LinkedIn 使用了dust.js http://akdubya.github.com/dustjs/
回答by mikerobi
Pick the template language that has an api and syntax you find most appealing. If you run in to performance problems, then you can look at alternatives.
选择具有您认为最吸引人的 API 和语法的模板语言。如果您遇到性能问题,那么您可以查看替代方案。
Unless you are constructing tables with thousands of rows, you probably won't notice a difference.
除非您正在构建具有数千行的表,否则您可能不会注意到差异。
Personally I use Google's Closure Templates. I chose it mainly because it also has a Java implementation. I have never done benchmarks.
我个人使用 Google 的Closure Templates。我选择它主要是因为它也有 Java 实现。我从来没有做过基准测试。