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

前端 未结 8 1492
心在旅途
心在旅途 2020-12-07 06:34

Major differences I\'ve seen are:

  • Handlebars adds #if, #unless, #with, and #each
  • Handlebars adds h
8条回答
  •  时光取名叫无心
    2020-12-07 07:13

    Mustache pros:

    • Very popular choice with a large, active community.
    • Server side support in many languages, including Java.
    • Logic-less templates do a great job of forcing you to separate presentation from logic.
    • Clean syntax leads to templates that are easy to build, read, and maintain.

    Mustache cons:

    • A little too logic-less: basic tasks (e.g. label alternate rows with different CSS classes) are difficult.
    • View logic is often pushed back to the server or implemented as a "lambda" (callable function).
    • For lambdas to work on client and server, you must write them in JavaScript.

    Handlebars pros:

    • Logic-less templates do a great job of forcing you to separate presentation from logic.
    • Clean syntax leads to templates that are easy to build, read, and maintain.
    • Compiled rather than interpreted templates.
    • Better support for paths than mustache (ie, reaching deep into a context object).
    • Better support for global helpers than mustache.

    Handlebars cons:

    • Requires server-side JavaScript to render on the server.

    Source: The client-side templating throwdown: mustache, handlebars, dust.js, and more

提交回复
热议问题