How do I choose the JavaScript template engine (JavaScript)?

Source: Internet
Author: User

Translator Jjfat

Date: 2012-9-17 Source: gbin1.com

With the increasing density of front-end development, the use of Ajax and JSON more and more frequently, we certainly avoid in the foreground development of a large number of use of tags, often see the following examples:

You have a JSON object, as follows:

var data={email: ' [email protected], gender: ' Male '}

Then you need to organize the JSON data into page content, as follows:

var email, gender;email= ' <div class= "mail" > ' + data.email+ </div> '; Gender= ' <div class= "gender" > ' + data.gender + </div> '; $ (' #contentwrapper '). Append (content). append (gender);

The code execution function is very simple, and the JSON data is generated from the content in the Web page as follows:

<div class= "Mail" >[email protected]</div>
<div class= "Gender" >Male</div>

If it's just a simple code combination, it might be nice, but if the page uses a similar structure, the later management costs will be relatively high unless the same programmer is maintained.

In order to solve this problem, we usually introduce the "JavaScript template engine concept", referring to the template, I believe everyone is not unfamiliar, if you have developed a server-side program, such as the Java EE related technology, it must be very familiar with Freemarker,sitemesh and other template class library, It can effectively help you organize and maintain code structure, improve code writing efficiency and reduce maintenance costs.

The current open source JavaScript template engine is many, the question that throws us is-how to choose a JS template engine?

In order to better help people choose the template engine, here is recommended a good tool site: Template-engine-chooser.

After opening this website, we can see a list of the more commonly used JS template engine, for example, Mustache.js,jquery's father John's Micorotemplate.js, as well as jquery Tmpl alternatives-jsrender and so on.

On the left side of the class library list are a series of questions, as follows:

    • Does the template need to be used on the client or server side?
    • What is the degree of logic complexity?
    • Is there a running speed requirement?
    • Do you need a pre-defined template?
    • Need partials support?
    • Need DOM structure or string string type?
    • In addition to the template tags, is not the development language consistent before and after rendering?

If you are also looking for a JS template, you must have some questions, or just the questions listed above. You only need to answer for different questions: Yes or no, the tool will automatically select the appropriate template.

Of course, the template here is not very full, but contains a more well-known template, I hope it can add more template selection later.

I hope you enjoy this tool! If you have any questions, please leave us a message!

Source: How do I choose the JavaScript template engine?

Http://itindex.net/detail/39743-%E9%80%89%E6%8B%A9-javascript-%E6%A8%A1%E6%9D%BF

How do I choose the JavaScript template engine (JavaScript)?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.