- The document discusses various Java template engines that can be used on the JVM including Thymeleaf, Mustache, Jade, and Scalate.
- A benchmark project was created to test the performance of these template engines in a Spring MVC application that renders a list of presentations.
- The results showed that Thymeleaf used more memory and was slower than commonly used engines like Freemarker and Velocity. Mustache performed very well. Scalate was over 100 seconds slower due to its layout mechanism.
2. About me
• Architect @ Hippo
• Worked on web based platforms since
2001 with PHP, XSLT, JSP,Velocity and
Freemarker
• Blogger at http://blog.jeroenreijn.com
10. Overview
• Available at http://www.thymeleaf.org/
• Java, DOM based template engine
• XML / XHTML / HTML5
• Full Spring MVC integration
• ‘Natural templating’
11. Natural templating
• From Wikipedia:
“The template can be a document as valid as
the final result, the engine syntax doesn't
break the document's structure”
18. Overview
• Available at https://mustache.github.com
• “logic-less” because there are no control
statements (i.e. if, else, loops, etc)
• Tags are specified using {{ }} (looks like a
mustache)
• Implemented by many languages: Java, Ruby,
JavaScript, Python, Erlang, PHP, ObjectiveC, .NET, C++, Go, ColdFusion, Scala, etc.
30. Overview
• Available at http://scalate.fusesource.org/
• Scala based Template Engine (ScalaTE)
• Templates are compiled as Scala objects
• Equivalent to using JSP, JSTL, JSP EL & Tiles /
Sitemesh
• Integration available for Spring, Play, Lift, ...
35. Benchmark project
• Simple Spring MVC application
• Multiple view resolvers
• Page that show a list of presentations
• Uses page layouts / fragments
• Uses i18n where possible
41. Performance
30,00s
Thymeleaf - v2.1.0
Jade4j - v0.3.17
Scalate - v1.6.1
Mustache - v1.8
Freemarker - v2.3.19
Velocity - v1.7
JSP - 2.1
26,50s
23,00s
19,50s
16,00s
12,50s
Total time taken for 25.000 requests (less is better)
42. Findings
• Thymeleaf used more memory and was
slower then the commonly used
• Scalate was a lot slower due to the layout
mechanism more than 100 seconds for
25.000 requests.
• Mustache performs really well
43. Tips
•
If you want designers to own your templates
consider Mustache or Thymeleaf
•
If you want developers to own your templates:
•
If you want to generate HTML / XML and DRY?
=> Jade
•
otherwise: JSP, Freemarker, etc