When comparing Handlebars.js vs XSLT in-browser implementation, the Slant community recommends Handlebars.js for most people. In the question“What are the best JavaScript templating engines?” Handlebars.js is ranked 2nd while XSLT in-browser implementation is ranked 31st. The most important reason people chose Handlebars.js is:
Handlebars is available as a JavaScript library, a [Django](https://github.com/yavorskiy/django-handlebars) module as well as [Java](https://github.com/jknack/handlebars.java), [Ruby](https://github.com/MSch/handlebars-ruby), [Scala](https://github.com/mwunsch/handlebars.scala), [.Net](https://github.com/rexm/Handlebars.Net) & [PHP](https://github.com/zordius/lightncandy) libraries, which means you can use it for frontend and backend templating in the language of your choice.
Ranked in these QuestionsQuestion Ranking
Pros
Pro Clean syntax
Handlebars's syntax is very readable and easy to understand.
Pro Clear separation of logic and markup
If something is not within {{
and }}
, it's not Handlebars. As a result, Handlebars "weaves" through HTML, instead of trying to become an invalid extension of it.
Pro Copy/Paste code from the internet
Examples for Bootstrap or other CSS frameworks are always in HTML. With Handlebards you can just copy and paste the examples in your code. With something like Pug (Jade) you have to convert the HTML to Pug (Jade) first.
Pro Easy to use for templating things other than HTML
The syntax allows the output to be any text and does not contrain the user to HTML output only. There are examples of handlebars being used to produce SQL, javascript and other programming language code.
Pro Easy to use any template also as partials
Templates may be nested and reusable parts can be factored out.
Pro Compiled rather than interpreted templates
Handlebars.js allows you to pre-compile your templates so that the loading time at the client end could be reduced when your templated page is loaded.
Pro Mustache compatible
You can import Mustache templates and add extra functionality, that's provided by Handlebars, on top of them.
Pro Good global helpers support
Pro Logic-less
By design, logic-less templates force you to separate concerns thus helping you avoid future problems with refactoring. It also allow templates to be used with multiple programming languages without changes.
Pro Good paths support
With Handlebars.js you can create bindings with variables inside any path in your application.
Pro Easy to define extensions
With a few lines of code, a new extension (control or templating function) can be implemented. It will be called by the compiled templates.
Pro Permits pipelining
I.e. apply one template on top of another.
Pro AOP model
With ability to split feature implementation apart from main codebase, development became quite more manageable. Example: for data of particular type you could define own rendering or render refine rules; pipelining allows incrementally change UI by adding/removing elements depend of parameters, data values, previously rendered content.
Pro Native multithreaded implementation
Only template engine which utilizes multithreading.
Pro Native pre-compilation available
In some browsers(IE) XSLT during load is compiled into DLL. In others pre-loaded template allows to skip recurring parsing .
Pro Accept native data out of JS heap
XML when stored, saved outside of JS heap, capable to work with amount of data 100x larger of JSON.
Pro Native implementation
Supported in all browsers, starting from IE5.
Pro Server side rendering
XSLT is available as in browser as on server side via various libs including highly optimized for CPU.
Cons
Con Hard to use documentation
Although the documentation exists and is fairly comprehensive, it's not always clearly written, and there is no search capacity.
Con Handlebars are still an HTML code
Handlebars use the standard HTML syntax with its own {{tags}} for templating. This doesn't add much to readability or design speed.
Con Using partials is cumbersome
"In order to use a partial, it must be registered" using some JavaScript method attached to some global variable.
Con Not much editor support
Handlebars.js doesn't seem to have many text editors that support things like auto-complete, syntax highlighting or error checking for it.
Con Does not play well with Angular.js
.. or any framework where you wish to compile handlebars.js template to the template understanable by the framework.
Con Lack of SDLC for in-browser development
It will take time to collect complete gentleman set: debugging, modular development, documenting, unit tests, etc. Please share if know the book on subject.
Con Verbose syntax
Takes time to get used to.
Con AOP model
Is complex to comprehend, justifiable on complex projects.