Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use JavaScript template engines?

Tags:

Here is an example of JavaScript template from Ben Nadel's demo single page long-lived AJAX application taken from: [source]

<script id="contact-list-item-template" type="application/template">      <li class="contact clear-fix">              <div class="summary">                     <a class="name">${name}</a>             </div>              <div class="actions">                     <a href="javascript:void( 0 )" class="more">more</a> &nbsp;|&nbsp;                     <a href="#/contacts/edit/${id}" class="edit">edit</a> &nbsp;|&nbsp;                     <a href="#/contacts/delete/${id}" class="delete">delete</a>             </div>              <dl class="details clear-fix">                     <dt>                             name:                     </dt>                     <dd>                             ${name}                     </dd>                     <dt>                             phone:                     </dt>                     <dd>                             ${phone}                     </dd>                     <dt>                             email:                     </dt>                     <dd>                             ${email}                     </dd>             </dl>      </li> 

I want to ask what is the purpose of using a JavaScript template engines like that? Is it for save of the bandwidth? Is it just a matter of Separation of concerns? Will it help in fighting the browser memory leaks problems?

When should I use template engine and when it is easier to go with raw HTML AJAX responses?

Related discussion:

JQuery templating engines

like image 430
Nikita Fedyashev Avatar asked Jan 16 '10 10:01

Nikita Fedyashev


People also ask

When should I use template engine?

Template engines are used when you want to rapidly build web applications that are split into different components. Templates also enable fast rendering of the server-side data that needs to be passed to the application. For example, you might want to have components such as body, navigation, footer, dashboard, etc.

Should I use a template engine or react?

At the moment, when we decide to implement some interactions, react-engine will be the winner. While react-engine rendering does not require JavaScript to run on the client side, it will enable SEO over the search. Template engines also have this SEO support, but with less impact.

Why do we need template engine in node JS?

Template engine helps us to create an HTML template with minimal code. Also, it can inject data into HTML template at client side and produce the final HTML.


1 Answers

Templating is a good solution in a few scenarios:

  • Loading all data from the server especially in rich list displays
  • Adding or updating new items in lists
  • Anywhere you need to add new complex content to the page
  • Anything that requires client side HTML rendering

Source : http://www.west-wind.com/Weblog/posts/509108.aspx

like image 101
Tarik Avatar answered Dec 07 '22 15:12

Tarik