1

I am programming cross-platform apps via PhoneGap and I learned that using template engines like Mustache will speed my apps up. I was just wondering why I should use a template engine. How will this help? I don't know the science of it. Can anyone explain?

tshepang
  • 12,111
  • 21
  • 91
  • 136
AJ Naidas
  • 1,424
  • 7
  • 25
  • 47

1 Answers1

2

Code which generates HTML tends to become verbose and hard to follow (read, debug, etc).

A templating engine can be thought of a a domain specific language for generating HTML (or, really, any kind of text… But I'm going to guess that you're generating HTML), making it easier to understand the structure and intent of the code.

David Wolever
  • 148,955
  • 89
  • 346
  • 502
  • it is said that it will help speed up my app. in what manner can it help? – AJ Naidas Dec 22 '11 at 04:25
  • That depends entirely on what you are doing now. However, it *will* likely speed up *development* of your app. – David Wolever Dec 22 '11 at 06:33
  • If you're doing ajax-updates on your app instead of full page reloads you can send data via json instead of html to the client. Mustache can then handle the json -> html transformation on the client, thus potentially saving lots of bandwidth/time. Another advantage is being able to stay DRY. (http://en.wikipedia.org/wiki/Don%27t_repeat_yourself) . Also see a related answer of mine that addresses Mustache as part of a common (good practice imho) workflow (http://stackoverflow.com/questions/7370056/accessibility-and-all-these-javascript-frameworks/7371629#7371629) – Geert-Jan Dec 22 '11 at 17:56
  • It is much more efficient than DOM-based markup creation, since it performs nothing but string operations and only hits the DOM to dump the finished markup in. – Barney Nov 07 '12 at 11:53