Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Shootout! Template
engines for the JVM
Jeroen Reijn | @jreijn | #jfall13
About me
• Engineer @ Hippo (CMS)
• Worked on web based platforms since
2001 with PHP, XSLT, JSP,Velocity and
Freemarker
•...
Session agenda
• General overview
• Interesting template engines
• Benchmark project
• Performance results
Template engine?
• What is a Template ?
• What is a Template Engine ?
• How many Java Template Engines ?
• Java-Source.net...
Most commonly used
• JSP
• Freemarker
• Velocity
Overview
Selection criteria
• Project activity
• Framework support
• Active Community
• Brings added value
• IDE support
Most interesting
• Thymeleaf
• Mustache
• Jade
• Scalate
Thymeleaf
Overview
• Available at http://www.thymeleaf.org/
• Java, DOM based template engine
• XML / XHTML / HTML5
• Full Spring MV...
Natural templating
• From Wikipedia:
“The template can be a document as valid as
the final result, the engine syntax doesn'...
JSP in browser
Thymeleaf in browser
Variables & Loops
• Variables
• Loops
Fragments
• Include fragment
• Define fragment based on th:fragment
{{ Mustache }}
Overview
• Available at https://mustache.github.com
• “logic-less” because there are no control
statements (i.e. if, else,...
Overview
• Java implementations:
• JMustache
• Mustache.java
• Not web specific
• Spring MVC integration as an 3th party
ad...
Variables
{
“greeting” : “Hello”,
“message” : “World”
}
{{greeting}} {{message}}
Data Template
Hello World
Output
Sections
{
"repo": [
{ "name": "resque" },
{ "name": "hub" },
{ "name": "rip" },
]
}
{{#repo}}
<li>{{name}}</li>
{{/repo}}...
Fragments
base.mustache:
<h2>Presentations</h2>
{{#presentations}}
{{> presentation}}
{{/presentations}}
presentation.must...
Jade
Jade
• Available at http://jade-lang.com
• Node.js Template engine
• Java Implementation: Jade4j
• Compact notation
Syntax
Result
Variables & Iterations
• Variables
• Iterations
Fragments
Overview
• Available at http://scalate.fusesource.org/
• Scala based Template Engine (ScalaTE)
• Templates are compiled as...
Template languages
• SSP (Scala Server Pages)
• SCAML (based on Ruby’s HAML)
• Mustache
• Jade
Scaml
• Based on HAML (HTML abstraction
markup language)
• Integrates Scala code
• Well formatted markup
• Similar to Jade
Variables & Loops
• Fragment support is possible
• Inline Scala code
Benchmark project
Benchmark project
• Simple Spring MVC application
• Multiple view resolvers
• Page that show a list of presentations
• Use...
Spring MVC
public class Presentation {
private Long id;
private String title;
private String speakerName;
private String summary;
pri...
Project available
• Project will be available as open source on
github.
• https://github.com/jreijn/spring-comparing-
temp...
Results!
Performance
0,00s
3,57s
7,14s
10,71s
14,29s
17,86s
21,43s
25,00s
Total time taken for 25.000 requests (less is better)
Thy...
Findings
• Thymeleaf used more memory and was
slower then the commonly used, but seems
great for the web.
• When using ‘la...
Tips
• If you want designers to own your templates
consider Mustache or Thymeleaf
• If you want developers to own your tem...
Thank you!
Questions?
@jreijn
j.reijn@onehippo.com
Shootout! Template engines for the JVM
Shootout! Template engines for the JVM
Shootout! Template engines for the JVM
Upcoming SlideShare
Loading in …5
×

of

Shootout! Template engines for the JVM Slide 1 Shootout! Template engines for the JVM Slide 2 Shootout! Template engines for the JVM Slide 3 Shootout! Template engines for the JVM Slide 4 Shootout! Template engines for the JVM Slide 5 Shootout! Template engines for the JVM Slide 6 Shootout! Template engines for the JVM Slide 7 Shootout! Template engines for the JVM Slide 8 Shootout! Template engines for the JVM Slide 9 Shootout! Template engines for the JVM Slide 10 Shootout! Template engines for the JVM Slide 11 Shootout! Template engines for the JVM Slide 12 Shootout! Template engines for the JVM Slide 13 Shootout! Template engines for the JVM Slide 14 Shootout! Template engines for the JVM Slide 15 Shootout! Template engines for the JVM Slide 16 Shootout! Template engines for the JVM Slide 17 Shootout! Template engines for the JVM Slide 18 Shootout! Template engines for the JVM Slide 19 Shootout! Template engines for the JVM Slide 20 Shootout! Template engines for the JVM Slide 21 Shootout! Template engines for the JVM Slide 22 Shootout! Template engines for the JVM Slide 23 Shootout! Template engines for the JVM Slide 24 Shootout! Template engines for the JVM Slide 25 Shootout! Template engines for the JVM Slide 26 Shootout! Template engines for the JVM Slide 27 Shootout! Template engines for the JVM Slide 28 Shootout! Template engines for the JVM Slide 29 Shootout! Template engines for the JVM Slide 30 Shootout! Template engines for the JVM Slide 31 Shootout! Template engines for the JVM Slide 32 Shootout! Template engines for the JVM Slide 33 Shootout! Template engines for the JVM Slide 34 Shootout! Template engines for the JVM Slide 35 Shootout! Template engines for the JVM Slide 36 Shootout! Template engines for the JVM Slide 37 Shootout! Template engines for the JVM Slide 38 Shootout! Template engines for the JVM Slide 39 Shootout! Template engines for the JVM Slide 40 Shootout! Template engines for the JVM Slide 41 Shootout! Template engines for the JVM Slide 42 Shootout! Template engines for the JVM Slide 43 Shootout! Template engines for the JVM Slide 44
Upcoming SlideShare
Shootout! template engines on the jvm
Next
Download to read offline and view in fullscreen.

83 Likes

Share

Download to read offline

Shootout! Template engines for the JVM

Download to read offline

These slides were from my JFall 2013 presentation about new template engines for the JVM. During this presentation I gave a short introduction to new and interesting template engines and show how they compare to the more well known: JSP, Velocity and Freemarker.

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Shootout! Template engines for the JVM

  1. 1. Shootout! Template engines for the JVM Jeroen Reijn | @jreijn | #jfall13
  2. 2. About me • Engineer @ Hippo (CMS) • Worked on web based platforms since 2001 with PHP, XSLT, JSP,Velocity and Freemarker • Blogger at http://blog.jeroenreijn.com
  3. 3. Session agenda • General overview • Interesting template engines • Benchmark project • Performance results
  4. 4. Template engine? • What is a Template ? • What is a Template Engine ? • How many Java Template Engines ? • Java-Source.net : 21 • Wikipedia: 17
  5. 5. Most commonly used • JSP • Freemarker • Velocity
  6. 6. Overview
  7. 7. Selection criteria • Project activity • Framework support • Active Community • Brings added value • IDE support
  8. 8. Most interesting • Thymeleaf • Mustache • Jade • Scalate
  9. 9. Thymeleaf
  10. 10. Overview • Available at http://www.thymeleaf.org/ • Java, DOM based template engine • XML / XHTML / HTML5 • Full Spring MVC integration • ‘Natural templating’
  11. 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”
  12. 12. JSP in browser
  13. 13. Thymeleaf in browser
  14. 14. Variables & Loops • Variables • Loops
  15. 15. Fragments • Include fragment • Define fragment based on th:fragment
  16. 16. {{ Mustache }}
  17. 17. 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, Objective- C, .NET, C++, Go, ColdFusion, Scala, etc.
  18. 18. Overview • Java implementations: • JMustache • Mustache.java • Not web specific • Spring MVC integration as an 3th party add-on
  19. 19. Variables { “greeting” : “Hello”, “message” : “World” } {{greeting}} {{message}} Data Template Hello World Output
  20. 20. Sections { "repo": [ { "name": "resque" }, { "name": "hub" }, { "name": "rip" }, ] } {{#repo}} <li>{{name}}</li> {{/repo}} Data Template <li>resque</li> <li>hub</li> <li>rip</li> Output
  21. 21. Fragments base.mustache: <h2>Presentations</h2> {{#presentations}} {{> presentation}} {{/presentations}} presentation.mustache: <h3>{{title}}</h3> <p>{{startTime}}</p> Template
  22. 22. Jade
  23. 23. Jade • Available at http://jade-lang.com • Node.js Template engine • Java Implementation: Jade4j • Compact notation
  24. 24. Syntax
  25. 25. Result
  26. 26. Variables & Iterations • Variables • Iterations
  27. 27. Fragments
  28. 28. 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, ...
  29. 29. Template languages • SSP (Scala Server Pages) • SCAML (based on Ruby’s HAML) • Mustache • Jade
  30. 30. Scaml • Based on HAML (HTML abstraction markup language) • Integrates Scala code • Well formatted markup • Similar to Jade
  31. 31. Variables & Loops • Fragment support is possible • Inline Scala code
  32. 32. Benchmark project
  33. 33. Benchmark project • Simple Spring MVC application • Multiple view resolvers • Page that show a list of presentations • Uses page layouts / fragments • Uses i18n where possible
  34. 34. Spring MVC
  35. 35. public class Presentation { private Long id; private String title; private String speakerName; private String summary; private String room; private Date startTime; private Date endTime; }
  36. 36. Project available • Project will be available as open source on github. • https://github.com/jreijn/spring-comparing- template-engines
  37. 37. Results!
  38. 38. Performance 0,00s 3,57s 7,14s 10,71s 14,29s 17,86s 21,43s 25,00s Total time taken for 25.000 requests (less is better) 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 * All tests were local, on hardware from 2010. Results might differ based on the actual implementation. For the latest results check the GitHub project from slide 39.
  39. 39. Findings • Thymeleaf used more memory and was slower then the commonly used, but seems great for the web. • When using ‘layouts’ instead of includes, Scalate was a factor 4 slower. • Mustache performed really well!
  40. 40. 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
  41. 41. Thank you! Questions? @jreijn j.reijn@onehippo.com
  • kungenw4301

    Jul. 16, 2019
  • ssuserac5423

    Sep. 4, 2018
  • hugheba

    Feb. 15, 2018
  • RobertoBraga13

    Dec. 15, 2017
  • soo5sin

    Jun. 14, 2017
  • kuangnlin

    May. 22, 2017
  • WuHongGuang

    Apr. 9, 2017
  • black4eyes

    Mar. 23, 2017
  • vivekdeveshwar

    Mar. 7, 2017
  • thoooppl

    Feb. 6, 2017
  • vietnguyen9634340

    Nov. 29, 2016
  • josejuanmontiel

    Sep. 7, 2016
  • ThomasSangJoonKim

    Jul. 31, 2016
  • talalUcef

    Jul. 22, 2016
  • sejoung

    Jul. 3, 2016
  • sanaes

    Jul. 3, 2016
  • SunukPark

    Jul. 3, 2016
  • gujjy97

    Jul. 3, 2016
  • ssuserae0cab

    Jul. 3, 2016
  • mindonal

    Jul. 2, 2016

These slides were from my JFall 2013 presentation about new template engines for the JVM. During this presentation I gave a short introduction to new and interesting template engines and show how they compare to the more well known: JSP, Velocity and Freemarker.

Views

Total views

79,899

On Slideshare

0

From embeds

0

Number of embeds

262

Actions

Downloads

272

Shares

0

Comments

0

Likes

83

×