Can be separated from the front and back of the code, the position is clear, so that the background program staff can better to complete the logic operation, and the front-end personnel posts more specialized and unified.
JS template engine More and more applications, now there have been dozens of kinds of JS template engine, the domestic major Internet companies have also developed their own JS template engine (Taobao Kissy template, Tencent's Arttemplate, Baidu Baidutemplate, etc.), How to choose a suitable one from so many complicated template engine, the author recently to the mainstream JS template engine (Mustache,dot,juicer,arttemplate,baidutemplate,handlebars, Underscore) did some research, share out the hope for everyone useful.
From these several indicators to compare the JS template engine:
1 File size – affects network transmission time 2 execution speed (performance) – Affects response speed, involves template parsing and rendering 3 syntax concise/easy-to-use/Flexible/Custom operators – Impact development efficiency and maintenance difficulty 4 error handling/debugging – Impact development efficiency and maintenance difficulty 5 security (XSS) – whether to prevent Xss
1 File size (after compression) mustache:5k dot:4k juicer:7.65k arttemplate (Tencent): 5k Baidutemplate (Baidu): 3k underscore (Arale): 11.7k– is not just a template, Also contains a lot of JS language enhancements handlebars (Arale): 30.5k
You can see that Arttemplate,juicer,dot is much faster than other template engines.
3 Syntax Concise/easy-to-use/flexible/Custom operators-impact development efficiency and maintenance difficulties
Mustache claims to be a logic-less template without a for, if...else ... syntax, but you can actually implement loops and branches, and you can implement more complex logic. Dot template syntax is flexible and easy to read. can be easily transformed into jquery plug-ins.
|The code is as follows||Copy Code|
4 Error handling/debugging – impact on development efficiency and maintenance difficulty Arttemplate has detailed error message information, easy to check, do not affect the continuation of the code behind the execution Kissy template error messages directly output in the page, rather than in the console. Do not affect the continuation of the following code Juicer console prompts template rendering error, does not affect the continuation of the code after the execution mustache no error message, does not affect the subsequent code to continue to perform other console script error js execution interrupted, do not know where the error
5 Security-very important. Whether to prevent XSS more than a few template engines all support HTML escape, prevent XSS
A final contrast: