4

Please explain in simple way what is the benefit of using a JavaScript templating engine?

We can write HTML quickly using Zen coding and even if we want some quick html code with data we can make our own code snippet collection and re-use it or use like http://html-ipsum.com/

and if we use any JavaScript templating engine then what about SEO and if JavaScript is disabled in users browser.

Jitendra Vyas
  • 148,487
  • 229
  • 573
  • 852

1 Answers1

1

The primary use for a JavaScript template library (See this article for an example of a template library http://stephenwalther.com/blog/archive/2010/11/30/an-introduction-to-jquery-templates.aspx) is to provide a more elegant way to create dynamic DOM elements. The old way was a lot of 'part' + of + ' ' + my + 'code is a string and ' + the + rest + ' is a collection of variables and markup'. While there isn't anything "wrong" with this per-say, it does lead to some very unreadable code.

The templates allow you to abstract this compilation to DOM placeholders so you can handle all of your HTML generation where it belongs, in the HTML.

Shawn Lehner
  • 1,293
  • 7
  • 14