What are the differences between Mustache.js and Handlebars.js?

Chad Johnson picture Chad Johnson · May 11, 2012 · Viewed 125.3k times · Source

Major differences I've seen are:

  • Handlebars adds #if, #unless, #with, and #each
  • Handlebars adds helpers
  • Handlebars templates are compiled (Mustache can be too)
  • Handlebars supports paths
  • Allows use of {{this}} in blocks (which outputs the current item's string value)
  • Handlebars.SafeString() (and maybe some other methods)
  • Handlebars is 2 to 7 times faster
  • Mustache supports inverted sections (i.e. if !x ...)

(Please correct me if I'm wrong with the above.)

Are there any other major differences I am missing?

Answer

frontendbeauty picture frontendbeauty · Aug 1, 2012

You've pretty much nailed it, however Mustache templates can also be compiled.

Mustache is missing helpers and the more advanced blocks because it strives to be logicless. Handlebars' custom helpers can be very useful, but often end up introducing logic into your templates.

Mustache has many different compilers (JavaScript, Ruby, Python, C, etc.). Handlebars began in JavaScript, now there are projects like django-handlebars, handlebars.java, handlebars-ruby, lightncandy (PHP), and handlebars-objc.