Shootout! Template engines for the JVM

Jeroen Reijn
Jeroen ReijnSoftware/Solution Architect at Luminis
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
• Blogger at http://blog.jeroenreijn.com
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 : 21
• Wikipedia: 17
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 MVC integration
• ‘Natural templating’
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”
JSP in browser
Thymeleaf in browser
Shootout! Template engines for the JVM
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, 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.
Overview
• Java implementations:
• JMustache
• Mustache.java
• Not web specific
• Spring MVC integration as an 3th party
add-on
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}}
Data Template
<li>resque</li>
<li>hub</li>
<li>rip</li>
Output
Fragments
base.mustache:
<h2>Presentations</h2>
{{#presentations}}
{{> presentation}}
{{/presentations}}
presentation.mustache:
<h3>{{title}}</h3>
<p>{{startTime}}</p>
Template
Jade
Jade
• Available at http://jade-lang.com
• Node.js Template engine
• Java Implementation: Jade4j
• Compact notation
Syntax
Result
Variables & Iterations
• Variables
• Iterations
Fragments
Shootout! Template engines for the JVM
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, ...
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
• Uses page layouts / fragments
• Uses i18n where possible
Spring MVC
public class Presentation {
private Long id;
private String title;
private String speakerName;
private String summary;
private String room;
private Date startTime;
private Date endTime;
}
Shootout! Template engines for the JVM
Project available
• Project will be available as open source on
github.
• https://github.com/jreijn/spring-comparing-
template-engines
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)
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.
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!
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
Thank you!
Questions?
@jreijn
j.reijn@onehippo.com
1 of 44

Recommended

Java Concurrency Gotchas by
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency GotchasAlex Miller
11.5K views57 slides
Spring Boot & WebSocket by
Spring Boot & WebSocketSpring Boot & WebSocket
Spring Boot & WebSocketMing-Ying Wu
8.6K views57 slides
Reactive Distributed Applications with Vert.x by
Reactive Distributed Applications with Vert.xReactive Distributed Applications with Vert.x
Reactive Distributed Applications with Vert.xRed Hat Developers
2.6K views52 slides
Spring Security e Spring Boot Aula - 2018 by
Spring Security e Spring Boot Aula - 2018Spring Security e Spring Boot Aula - 2018
Spring Security e Spring Boot Aula - 2018André Luiz Forchesatto
3.4K views23 slides
Java security by
Java securityJava security
Java securityAnkush Kumar
2.9K views23 slides
Vertx by
VertxVertx
VertxAlvaro Videla
7.7K views60 slides

More Related Content

What's hot

Introduction to Spring Framework by
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework Serhat Can
26K views52 slides
Lecture 3: Servlets - Session Management by
Lecture 3:  Servlets - Session ManagementLecture 3:  Servlets - Session Management
Lecture 3: Servlets - Session ManagementFahad Golra
2.8K views33 slides
Beautiful Bash: Let's make reading and writing bash scripts fun again! by
Beautiful Bash: Let's make reading and writing bash scripts fun again!Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!Aaron Zauner
14.5K views32 slides
Lambda Expressions in Java 8 by
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8icarter09
1.9K views32 slides
JavaScript - Chapter 9 - TypeConversion and Regular Expressions by
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions WebStackAcademy
360 views31 slides
Introduction to Spring Boot by
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring BootPurbarun Chakrabarti
1K views18 slides

What's hot(20)

Introduction to Spring Framework by Serhat Can
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Serhat Can26K views
Lecture 3: Servlets - Session Management by Fahad Golra
Lecture 3:  Servlets - Session ManagementLecture 3:  Servlets - Session Management
Lecture 3: Servlets - Session Management
Fahad Golra2.8K views
Beautiful Bash: Let's make reading and writing bash scripts fun again! by Aaron Zauner
Beautiful Bash: Let's make reading and writing bash scripts fun again!Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!
Aaron Zauner14.5K views
Lambda Expressions in Java 8 by icarter09
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
icarter091.9K views
JavaScript - Chapter 9 - TypeConversion and Regular Expressions by WebStackAcademy
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
WebStackAcademy360 views
Introduction to Javascript By Satyen by Satyen Pandya
Introduction to Javascript By  SatyenIntroduction to Javascript By  Satyen
Introduction to Javascript By Satyen
Satyen Pandya420 views
Event In JavaScript by ShahDhruv21
Event In JavaScriptEvent In JavaScript
Event In JavaScript
ShahDhruv213.2K views
TestNG Session presented in Xebia XKE by Abhishek Yadav
TestNG Session presented in Xebia XKETestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKE
Abhishek Yadav503 views
TypeScript Introduction by Dmitry Sheiko
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
Dmitry Sheiko7.4K views
Angular - Chapter 7 - HTTP Services by WebStackAcademy
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
WebStackAcademy648 views
Spring Web MVC by zeeshanhanif
Spring Web MVCSpring Web MVC
Spring Web MVC
zeeshanhanif10.6K views
SOLID Design Principles by Andreas Enbohm
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
Andreas Enbohm18.7K views
Spring Boot in Action by Alex Movila
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
Alex Movila3K views
javascript objects by Vijay Kalyan
javascript objectsjavascript objects
javascript objects
Vijay Kalyan5.1K views
Nodejs - A performance que eu sempre quis ter by Emerson Macedo
Nodejs - A performance que eu sempre quis terNodejs - A performance que eu sempre quis ter
Nodejs - A performance que eu sempre quis ter
Emerson Macedo4.2K views

Viewers also liked

Shootout! template engines on the jvm by
Shootout! template engines on the jvmShootout! template engines on the jvm
Shootout! template engines on the jvmNLJUG
6K views44 slides
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf by
Spring I/O 2012: Natural Templating in Spring MVC with ThymeleafSpring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with ThymeleafThymeleaf
14.3K views51 slides
The typesafe builder pattern by
The typesafe builder patternThe typesafe builder pattern
The typesafe builder patternGregor Heine
1.4K views44 slides
Thymeleaf, will it blend? by
Thymeleaf, will it blend?Thymeleaf, will it blend?
Thymeleaf, will it blend?Jasha Joachimsthal
6.9K views20 slides
Thymeleaf Introduction by
Thymeleaf IntroductionThymeleaf Introduction
Thymeleaf IntroductionAnthony Chen
4K views17 slides
rmp by
rmprmp
rmpmadhwanisneha
125 views6 slides

Viewers also liked(20)

Shootout! template engines on the jvm by NLJUG
Shootout! template engines on the jvmShootout! template engines on the jvm
Shootout! template engines on the jvm
NLJUG6K views
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf by Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with ThymeleafSpring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Thymeleaf14.3K views
The typesafe builder pattern by Gregor Heine
The typesafe builder patternThe typesafe builder pattern
The typesafe builder pattern
Gregor Heine1.4K views
Introducing Scalate, the Scala Template Engine by James Strachan
Introducing Scalate, the Scala Template EngineIntroducing Scalate, the Scala Template Engine
Introducing Scalate, the Scala Template Engine
James Strachan6.1K views
Building a relevance platform with Couchbase and Elasticsearch by Jeroen Reijn
Building a relevance platform with Couchbase and ElasticsearchBuilding a relevance platform with Couchbase and Elasticsearch
Building a relevance platform with Couchbase and Elasticsearch
Jeroen Reijn2.5K views
Real-time visitor analysis with Couchbase and Elastichsearch by Jeroen Reijn
Real-time visitor analysis with Couchbase and ElastichsearchReal-time visitor analysis with Couchbase and Elastichsearch
Real-time visitor analysis with Couchbase and Elastichsearch
Jeroen Reijn3.7K views
Basic web application development with Apache Cocoon 2.1 by Jeroen Reijn
Basic web application development with  Apache Cocoon 2.1Basic web application development with  Apache Cocoon 2.1
Basic web application development with Apache Cocoon 2.1
Jeroen Reijn2.7K views
Hippo GetTogether: The architecture behind Hippos relevance platform by Jeroen Reijn
Hippo GetTogether: The architecture behind Hippos relevance platformHippo GetTogether: The architecture behind Hippos relevance platform
Hippo GetTogether: The architecture behind Hippos relevance platform
Jeroen Reijn2.5K views
Continuous Delivery in a content centric world by Jeroen Reijn
Continuous Delivery in a content centric worldContinuous Delivery in a content centric world
Continuous Delivery in a content centric world
Jeroen Reijn483 views
MongoDB and the Internet of Things by MongoDB
MongoDB and the Internet of ThingsMongoDB and the Internet of Things
MongoDB and the Internet of Things
MongoDB3K views
Thymeleafのすすめ by eiryu
ThymeleafのすすめThymeleafのすすめ
Thymeleafのすすめ
eiryu6K views
Setting up a free open source java e-commerce website by Csaba Toth
Setting up a free open source java e-commerce websiteSetting up a free open source java e-commerce website
Setting up a free open source java e-commerce website
Csaba Toth7.7K views
Conferences i/o Webinar: Benefits of PowerPoint Integration by John Pytel
Conferences i/o Webinar: Benefits of PowerPoint IntegrationConferences i/o Webinar: Benefits of PowerPoint Integration
Conferences i/o Webinar: Benefits of PowerPoint Integration
John Pytel823 views
Introducing thymeleaf by eiryu
Introducing thymeleafIntroducing thymeleaf
Introducing thymeleaf
eiryu1.1K views
SpringDataJPA - 스프링 캠프 by Younghan Kim
SpringDataJPA - 스프링 캠프SpringDataJPA - 스프링 캠프
SpringDataJPA - 스프링 캠프
Younghan Kim18.1K views

Similar to Shootout! Template engines for the JVM

Project First presentation about introduction to technologies to be used by
Project First presentation about introduction to technologies to be usedProject First presentation about introduction to technologies to be used
Project First presentation about introduction to technologies to be usedarya krazydude
211 views27 slides
Meanstack Introduction by Kishore Chandra by
Meanstack Introduction by Kishore ChandraMeanstack Introduction by Kishore Chandra
Meanstack Introduction by Kishore ChandraKishore Chandra
138 views39 slides
1.6 米嘉 gobuildweb by
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildwebLeo Zhou
59 views23 slides
Intro to SPA using JavaScript & ASP.NET by
Intro to SPA using JavaScript & ASP.NETIntro to SPA using JavaScript & ASP.NET
Intro to SPA using JavaScript & ASP.NETAlan Hecht
8.2K views47 slides
MEAN Stack by
MEAN StackMEAN Stack
MEAN StackKrishnaprasad k
734 views39 slides

Similar to Shootout! Template engines for the JVM(20)

Project First presentation about introduction to technologies to be used by arya krazydude
Project First presentation about introduction to technologies to be usedProject First presentation about introduction to technologies to be used
Project First presentation about introduction to technologies to be used
arya krazydude211 views
Meanstack Introduction by Kishore Chandra by Kishore Chandra
Meanstack Introduction by Kishore ChandraMeanstack Introduction by Kishore Chandra
Meanstack Introduction by Kishore Chandra
Kishore Chandra138 views
1.6 米嘉 gobuildweb by Leo Zhou
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb
Leo Zhou59 views
Intro to SPA using JavaScript & ASP.NET by Alan Hecht
Intro to SPA using JavaScript & ASP.NETIntro to SPA using JavaScript & ASP.NET
Intro to SPA using JavaScript & ASP.NET
Alan Hecht8.2K views
WebNetConf 2012 - Single Page Apps by Pop Apps
WebNetConf 2012 - Single Page AppsWebNetConf 2012 - Single Page Apps
WebNetConf 2012 - Single Page Apps
Pop Apps1K views
The Characteristics of a Successful SPA by Gil Fink
The Characteristics of a Successful SPAThe Characteristics of a Successful SPA
The Characteristics of a Successful SPA
Gil Fink1.8K views
After the LAMP, it's time to get MEAN by Jeff Fox
After the LAMP, it's time to get MEANAfter the LAMP, it's time to get MEAN
After the LAMP, it's time to get MEAN
Jeff Fox752 views
Backbonification for dummies - Arrrrug 10/1/2012 by Dimitri de Putte
Backbonification for dummies - Arrrrug 10/1/2012Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012
Dimitri de Putte902 views
Introduction to web application development with Vue (for absolute beginners)... by Lucas Jellema
Introduction to web application development with Vue (for absolute beginners)...Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...
Lucas Jellema58 views
SoCal Code Camp 2011 - ASP.NET 4.5 by Jon Galloway
SoCal Code Camp 2011 - ASP.NET 4.5SoCal Code Camp 2011 - ASP.NET 4.5
SoCal Code Camp 2011 - ASP.NET 4.5
Jon Galloway594 views
End to-End SPA Development Using ASP.NET and AngularJS by Gil Fink
End to-End SPA Development Using ASP.NET and AngularJSEnd to-End SPA Development Using ASP.NET and AngularJS
End to-End SPA Development Using ASP.NET and AngularJS
Gil Fink2.9K views
Frameworks Galore: A Pragmatic Review by netc2012
Frameworks Galore: A Pragmatic ReviewFrameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic Review
netc2012732 views
Isomorphic JavaScript – future of the web by Sigma Software
Isomorphic JavaScript – future of the webIsomorphic JavaScript – future of the web
Isomorphic JavaScript – future of the web
Sigma Software732 views
PLAT-8 Spring Web Scripts and Spring Surf by Alfresco Software
PLAT-8 Spring Web Scripts and Spring SurfPLAT-8 Spring Web Scripts and Spring Surf
PLAT-8 Spring Web Scripts and Spring Surf
Alfresco Software1.5K views
What is Mean Stack Development ? by Balajihope
What is Mean Stack Development ?What is Mean Stack Development ?
What is Mean Stack Development ?
Balajihope158 views

Recently uploaded

Zero to Automated in Under a Year by
Zero to Automated in Under a YearZero to Automated in Under a Year
Zero to Automated in Under a YearNetwork Automation Forum
15 views23 slides
PRODUCT LISTING.pptx by
PRODUCT LISTING.pptxPRODUCT LISTING.pptx
PRODUCT LISTING.pptxangelicacueva6
14 views1 slide
Democratising digital commerce in India-Report by
Democratising digital commerce in India-ReportDemocratising digital commerce in India-Report
Democratising digital commerce in India-ReportKapil Khandelwal (KK)
18 views161 slides
"Running students' code in isolation. The hard way", Yurii Holiuk by
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk Fwdays
17 views34 slides
Future of Indian ConsumerTech by
Future of Indian ConsumerTechFuture of Indian ConsumerTech
Future of Indian ConsumerTechKapil Khandelwal (KK)
22 views68 slides
HTTP headers that make your website go faster - devs.gent November 2023 by
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023Thijs Feryn
22 views151 slides

Recently uploaded(20)

"Running students' code in isolation. The hard way", Yurii Holiuk by Fwdays
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk
Fwdays17 views
HTTP headers that make your website go faster - devs.gent November 2023 by Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn22 views
Unit 1_Lecture 2_Physical Design of IoT.pdf by StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec12 views
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe by Simone Puorto
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe
Simone Puorto12 views
The Forbidden VPN Secrets.pdf by Mariam Shaba
The Forbidden VPN Secrets.pdfThe Forbidden VPN Secrets.pdf
The Forbidden VPN Secrets.pdf
Mariam Shaba20 views
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab21 views
Future of AR - Facebook Presentation by ssuserb54b561
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
ssuserb54b56115 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi132 views
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb14 views
"Node.js Development in 2024: trends and tools", Nikita Galkin by Fwdays
"Node.js Development in 2024: trends and tools", Nikita Galkin "Node.js Development in 2024: trends and tools", Nikita Galkin
"Node.js Development in 2024: trends and tools", Nikita Galkin
Fwdays11 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive

Shootout! Template engines for the JVM