开发者

JavaScript template engines for mobile web applications [closed]

开发者 https://www.devze.com 2023-04-06 12:33 出处:网络
Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tool开发者_如何学Cs, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 7 years ago.

Improve this question

I'm building an application using jQTouch. I'd like to take advantage of one of the JavaScript template engines to avoid manual generation of HTML using data returned from JSON services.

Which engines are known to provide good mobile compatibility, and coexist well with jQTouch (and jQuery Mobile)?


Compatibility is not a problem if your intention is to use the engine only in mobile browsers/wrappers (or modern desktop browsers). Moreover, the performance is essential for web-based mobile applications.

So you have a couple of options:

  • jQuery templates
    • Pros: more or less well documented, widely used.
    • Cons: it is no longer being maintained by jQuery team, ie forever beta.
  • Clousure templates:
    • Pros: rich construction blocks - ifs, foreach, etc. Can compile the same template for multiple targets (js, java ...)
    • Cons: you'll have to execute the compiler to compile the template even on development stage, that is, client side compilation is not available. For me, it's a pain. Although it's very powerful, seems like "a bazooka to kill a mosquito" if used only for web.
  • distal
    • Never used, but it seems more like a "dynamic UI engine" like knockout or angularjs than a template engine.
  • mustache (I pick this one).
    • It has a very simple (yet powerful) syntax - you can learn mustache in 15 minutes - and by not providing "complex blocks" it enforces you to create good models instead of fat and complex templates, with a bunch of ifs, whiles and foreachs.
    • There are engine versions for more than 10 languages, including javascript, .net, java, ruby...
    • Cons: The simplicity in a few cases becomes limiting
  • mustache + hogan
    • Hogan is a compiler for the Mustache templating language written by the guys from twitter.
    • It is really fast
    • It can compile templates at runtime or pre-compile for packaging tools.
    • AMD compliant (has a plugin for requirejs)
    • Is in active development
    • Cons: poorly documented.

mustache: http://mustache.github.com/mustache.5.html

hogan: https://github.com/twitter/hogan.js


I use Distal templates and it works on the iPhone.


I used jQuery templates for a large-scale jQuery Mobile single page app on ASP.NET MVC 3. Putting all the template files in a partial view worked quite well. Templates worked well on all browsers that jQuery Mobile supported including IE 6,7,8.

https://github.com/jquery/jquery-tmpl


How "big" is the application? If you are primarily after templates you should give Google Closure Templates a try -

http://code.google.com/closure/templates/

Some concepts -

http://code.google.com/closure/templates/docs/concepts.html

0

精彩评论

暂无评论...
验证码 换一张
取 消