When comparing Pug (previously Jade) vs Handlebars.js, the Slant community recommends Pug (previously Jade) for most people. In the question“What are the best HTML preprocessors?” Pug (previously Jade) is ranked 1st while Handlebars.js is ranked 3rd. The most important reason people chose Pug (previously Jade) is:
One of the distinguishing features of Jade is its clean syntax. Elements are created with CSS selector syntax which makes the template consistent with your style sheet and JavaScript element selector library.
Ranked in these QuestionsQuestion Ranking
Pros
Pro Clean syntax
One of the distinguishing features of Jade is its clean syntax. Elements are created with CSS selector syntax which makes the template consistent with your style sheet and JavaScript element selector library.
Pro Allows writing inline JavaScript
Jade allows embedding regular JavaScript code directly within the template.
Pro Reuse code in other langauges
In addition to JavaScript, you can reuse Jade templates in Scala, PHP, Ruby, Python and Java.
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.
Cons
Con Unforgiving in case of indentation errors
The structure is entirely determined by the indentation. That means that indentation errors will ruin the end result, often without an easy way to find the error. Indentation errors are easily introduced by copy-pasting, by rearranging code and by working in a team where not everyone uses the same indentation style. (E.g tabs vs. spaces.)
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.