Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Common approaches to using a HTML template are to:

Use a library like Mustache

...

Mustache is a fine templating library and liked by a lot of people. However I see these drawbacks:

  • 600 lines of code, 9 contributors for

    5

    20 line code problem

  • 9 contributors

  • It requires programmers to pick {{}} or

    - it’s therefore difficult to understand completely.

  • All data is automatically escaped for special characters in HTML.

    • In mustache programmers need to learn from the school of hard knocks to always use {{{ }}}

    • What parts of Mustache are good?

      • Offers caching of compiling templates

        • Is this premature optimization?

      • Optional special character escaping of some values - using triple {{{}}} bracket notation.

      • Simple if and if not present solution - show what to print if something is not there.

      • Expressed in one file - good

    • What parts of Mustache are not good?

      • Lot of contributors for something for should be simple

    ECMA literals also could be used as templating mechanism by themselves.

  • It has no unnecessary features like

    • Template caching - which exchanges speed for memory usage and adds complexity. This is premature optimization. The simpler library will be faster by design.

    • There are no fancy callback features to tempt developers to write complicated code. It’s only going to work with an array of data.

    • No if statements if data isn’t present - encouraging separation of concerns.