SlideShare une entreprise Scribd logo
1  sur  24
Optimizing Content Managed
JavaScript Applications
with Magnolia
Hi, I am Adam Galloway
Development Lead at NRG Edge
We are from Philadelphia, PA
WE ARE A BANK TECHNOLOGY SOLUTIONS & SERVICES
COMPANY
Let’s talk about Hulk Hogan
I mean Hulk and Hogan… js
Hogan.js
• A lightweight JavaScript Mustache
templating engine (2.5K)
• Created by Twitter
• No framework dependencies
• Works great by itself but also integrates
easily with Backbone.js and Marionette.js
Great but…
• Template markup is stored in a string?
– That seems like a pain to maintain.
• The string has to be compiled before
rendering?
– That seems like a performance concern.
• This is all happens in the browser before the
page can load?
– That seems like a bad time to slow things down.
Hulk enters the ring
• Hulk is a node.js command line tool
offered by Hogan.js
• Hulk turns Mustache markup into
precompiled ready-to-use JavaScript
objects
• It reads in markup from multiple text files
with the .hogan file extension
• It outputs a minified .js file that can be
included in your html as a regular
JavaScript file
It turns this:
Into this:
It’s getting better
How this helps
• We are no longer dealing
with building strings in
JavaScript
• We no longer need the
browser to compile
anything
• It combines multiple
templates into one
resource
How this hurts
• This is a command line
tool
• It needs node.js to run
• It becomes another step
in the build process
• It doesn’t seem very
friendly to content
management
How to make it work for us
• Let’s compile the templates on the server
side in Java when we can’t use node.js
• Let’s do this in a servlet so we don’t have
to do this only at build time
• Let’s content manage the markup used in
the templates
javax.script.ScriptEngine
• Java 6 includes the ScriptEngine API that
allows running ECMAScript from Java
• The ScriptEngine allows passing Java
variables to and from the JavaScript being
executed
• We can use ScriptEngine in a Servlet and we
can pass it InputStreams and Strings to be
executed*
*Thanks to a great blog post by Christian Grobmeier for
precompiling Hogan.js in a Struts 2 action
Sample ScriptEngine code
Magnolia meets Hogan
• We can easily create Magnolia templates
that contain Mustache markup ready to be
used as a Hogan.js templates
• We can easily query mgnl:components
and mgnl:areas and then compile them
into one resource (like Hulk does with
.hogan files)
• We can recompile whenever content
changes and we can cache the results
easily
A very simple example.ftl
Notice the Mustache and Freemarker code playing nicely
together
Now we are content managed!
• We are now content managing the Hogan templates
• We are now precompiling the Hogan templates
• But wait there’s more!
• In this servlet we can also
– clean the html in the Hogan markup before we compile it
– use YUI Compressor to compress the JavaScript
produced by compiling
– cache the cleaned compressed compiled result
– gzip the response
Ok, now I see a bunch of curly
brackets
• Using this .ftl in Magnolia Author you will
see a lot of Mustache placeholders in the
editor
• Can’t we just replace the placeholders with
sample data?
• Yes, and because each view is mocked up
on the server side we can create a Java
filter to use Mustache to replace the
placeholders with sample values
Steps to put it all together
1. Take an existing .hogan template file that you would use with
hulk and add it to Magnolia as an .ftl template
2. Add Freemarker code and Magnolia components needed to
manage any content
3. Add a filter to show sample data in Magnolia Author
4. Add a servlet to query the content from Magnolia,
precompile it using ScriptEngine and optimize it using YUI
Compressor
5. Include the JavaScript returned by the servlet in our web
application
6. Use the Hogan template objects just like any other Hogan
template
Let’s see a quick demo
What about other frameworks -
Handlebars
• Handlebars is another commonly used
Mustache templating engine
• Thankfully nearly all of this code can be
reused with Handlebars
• Simply change the libraries used in the
precompile servlet and then change the
compilation code from:
– Hogan.compile(templateString, {asString: true});
to:
– Handlebars.precompile(templateString).toString();
What about other frameworks –
Angular.js
• Angular.js actively renders templates instead
of compiling and merging them with data at
render time
• We can still generate a single JavaScript file
containing minified content managed
templates
• The code generated by the servlet would be
similar to this:
“I fear no man, no beast or evil,
brother.”
- HULK HOGAN
And neither should we.
ANY QUESTIONS?
Sources
• Rocky statue image from Wikimedia - creative
commons attribution
– http://wikimediafoundation.org/wiki/File:9.26.06RockyStatueByLuigiNovi1.jpg
• Hulk Hogan image from flickr - creative commons
attribution
– http://m.flickr.com/#/photos/hodgers/3415258483/sizes/l/
• Example code using ScriptEngine from Christian
Grobmeier’s blog
– http://www.grobmeier.de/precompiling-hogan-jsmustache-templates-on-a-java-server-with-
struts-2-16012012.html
• Jsfiddle for the example Hogan.js template
– http://jsfiddle.net/qDBXF/

Contenu connexe

Tendances

From server generated pages to client app in a micro-services world
From server generated pages to client app in a micro-services worldFrom server generated pages to client app in a micro-services world
From server generated pages to client app in a micro-services world
Assaf Gannon
 
Integration Testing With Cucumber How To Test Anything J A O O 2009
Integration Testing With  Cucumber    How To Test Anything    J A O O 2009Integration Testing With  Cucumber    How To Test Anything    J A O O 2009
Integration Testing With Cucumber How To Test Anything J A O O 2009
Dr Nic Williams
 

Tendances (20)

Angular on ASP.NET MVC 6
Angular on ASP.NET MVC 6Angular on ASP.NET MVC 6
Angular on ASP.NET MVC 6
 
Rails review
Rails reviewRails review
Rails review
 
Writing a Fullstack Application with Javascript - Remote media player
Writing a Fullstack Application with Javascript - Remote media playerWriting a Fullstack Application with Javascript - Remote media player
Writing a Fullstack Application with Javascript - Remote media player
 
Test Automation Framework using Cucumber BDD Overview - part 2
Test Automation Framework using Cucumber BDD Overview - part 2Test Automation Framework using Cucumber BDD Overview - part 2
Test Automation Framework using Cucumber BDD Overview - part 2
 
Frontend as a first class citizen
Frontend as a first class citizenFrontend as a first class citizen
Frontend as a first class citizen
 
From server generated pages to client app in a micro-services world
From server generated pages to client app in a micro-services worldFrom server generated pages to client app in a micro-services world
From server generated pages to client app in a micro-services world
 
Front-End Tools and Workflows
Front-End Tools and WorkflowsFront-End Tools and Workflows
Front-End Tools and Workflows
 
Building rest services using aspnetwebapi
Building rest services using aspnetwebapiBuilding rest services using aspnetwebapi
Building rest services using aspnetwebapi
 
Patterns in JavaScript
Patterns in JavaScriptPatterns in JavaScript
Patterns in JavaScript
 
Fastest to Mobile with Scalatra + Swagger
Fastest to Mobile with Scalatra + SwaggerFastest to Mobile with Scalatra + Swagger
Fastest to Mobile with Scalatra + Swagger
 
ASP.NET MVC, AngularJS CRUD for Azerbaijan Technical University
ASP.NET MVC, AngularJS CRUD for Azerbaijan Technical UniversityASP.NET MVC, AngularJS CRUD for Azerbaijan Technical University
ASP.NET MVC, AngularJS CRUD for Azerbaijan Technical University
 
EXPERTALKS: Jul 2012 - Build using Gradle
EXPERTALKS: Jul 2012 - Build using GradleEXPERTALKS: Jul 2012 - Build using Gradle
EXPERTALKS: Jul 2012 - Build using Gradle
 
Building a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring BootBuilding a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring Boot
 
Alfresco Mvc - a seamless integration with Spring Mvc
Alfresco Mvc - a seamless integration with Spring MvcAlfresco Mvc - a seamless integration with Spring Mvc
Alfresco Mvc - a seamless integration with Spring Mvc
 
Integration Testing With Cucumber How To Test Anything J A O O 2009
Integration Testing With  Cucumber    How To Test Anything    J A O O 2009Integration Testing With  Cucumber    How To Test Anything    J A O O 2009
Integration Testing With Cucumber How To Test Anything J A O O 2009
 
ReactPHP + Symfony
ReactPHP + SymfonyReactPHP + Symfony
ReactPHP + Symfony
 
MVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative WebtechnologieMVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative Webtechnologie
 
SpringPeople Building Web Sites with ASP.NET MVC FRAMEWORK
SpringPeople Building Web Sites with ASP.NET MVC FRAMEWORKSpringPeople Building Web Sites with ASP.NET MVC FRAMEWORK
SpringPeople Building Web Sites with ASP.NET MVC FRAMEWORK
 
How to Build Single Page HTML5 Apps that Scale
How to Build Single Page HTML5 Apps that ScaleHow to Build Single Page HTML5 Apps that Scale
How to Build Single Page HTML5 Apps that Scale
 
Why use Go for web development?
Why use Go for web development?Why use Go for web development?
Why use Go for web development?
 

Similaire à Optimizing Content Managed Rich JavaScript Apps

Instagram filters (8 24)
Instagram filters (8 24)Instagram filters (8 24)
Instagram filters (8 24)
Ivy Rueb
 
Web development today
Web development todayWeb development today
Web development today
Jaydev Gajera
 
Introduction to Grails 2013
Introduction to Grails 2013Introduction to Grails 2013
Introduction to Grails 2013
Gavin Hogan
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scripts
ch samaram
 

Similaire à Optimizing Content Managed Rich JavaScript Apps (20)

Instagram filters (8 24)
Instagram filters (8 24)Instagram filters (8 24)
Instagram filters (8 24)
 
Instagram filters (8 24)
Instagram filters (8 24)Instagram filters (8 24)
Instagram filters (8 24)
 
Welcome to React.pptx
Welcome to React.pptxWelcome to React.pptx
Welcome to React.pptx
 
Javantura v4 - FreeMarker in Spring web - Marin Kalapać
Javantura v4 - FreeMarker in Spring web - Marin KalapaćJavantura v4 - FreeMarker in Spring web - Marin Kalapać
Javantura v4 - FreeMarker in Spring web - Marin Kalapać
 
Django course
Django courseDjango course
Django course
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
 
Web development today
Web development todayWeb development today
Web development today
 
Web Technology Part 2
Web Technology Part 2Web Technology Part 2
Web Technology Part 2
 
Instagram filters
Instagram filters Instagram filters
Instagram filters
 
Introduction to Lightning Web Components
Introduction to Lightning Web ComponentsIntroduction to Lightning Web Components
Introduction to Lightning Web Components
 
Lightning web components
Lightning web components Lightning web components
Lightning web components
 
Untangling spring week11
Untangling spring week11Untangling spring week11
Untangling spring week11
 
Swagger - Making REST APIs friendlier
Swagger - Making REST APIs friendlierSwagger - Making REST APIs friendlier
Swagger - Making REST APIs friendlier
 
Introduction to Grails 2013
Introduction to Grails 2013Introduction to Grails 2013
Introduction to Grails 2013
 
Django Girls Tutorial
Django Girls TutorialDjango Girls Tutorial
Django Girls Tutorial
 
Modern websites in 2020 and Joomla
Modern websites in 2020 and JoomlaModern websites in 2020 and Joomla
Modern websites in 2020 and Joomla
 
12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQL12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQL
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scripts
 
javascript 1
javascript 1javascript 1
javascript 1
 
Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework
 

Plus de Magnolia

Plus de Magnolia (20)

The SEO Workflow
The SEO WorkflowThe SEO Workflow
The SEO Workflow
 
Magnolia 6 release walkthrough
Magnolia 6 release walkthroughMagnolia 6 release walkthrough
Magnolia 6 release walkthrough
 
Buzzword bingo: The real deal behind omnichannel, personalization and headless
Buzzword bingo: The real deal behind  omnichannel, personalization and headlessBuzzword bingo: The real deal behind  omnichannel, personalization and headless
Buzzword bingo: The real deal behind omnichannel, personalization and headless
 
Developing Magnolia based sites correctly, quickly and efficiently
Developing Magnolia based sites correctly, quickly and efficientlyDeveloping Magnolia based sites correctly, quickly and efficiently
Developing Magnolia based sites correctly, quickly and efficiently
 
Integrating e-Commerce into your Customer Experience
Integrating e-Commerce into your Customer ExperienceIntegrating e-Commerce into your Customer Experience
Integrating e-Commerce into your Customer Experience
 
Customer Engagement in the Digital Era
Customer Engagement in the Digital EraCustomer Engagement in the Digital Era
Customer Engagement in the Digital Era
 
The Age of the IOT & Digital Business
The Age of the IOT & Digital BusinessThe Age of the IOT & Digital Business
The Age of the IOT & Digital Business
 
Using Magnolia in a Microservices Architecture
Using Magnolia in a Microservices ArchitectureUsing Magnolia in a Microservices Architecture
Using Magnolia in a Microservices Architecture
 
A modern front end development workflow for Magnolia at Atlassian
A modern front end development workflow for Magnolia at AtlassianA modern front end development workflow for Magnolia at Atlassian
A modern front end development workflow for Magnolia at Atlassian
 
Magnolia Conference 2015 - Pascal Mangold's keynote
Magnolia Conference 2015 - Pascal Mangold's keynoteMagnolia Conference 2015 - Pascal Mangold's keynote
Magnolia Conference 2015 - Pascal Mangold's keynote
 
Product keynote - introducing Magnolia 5.4
Product keynote - introducing Magnolia 5.4Product keynote - introducing Magnolia 5.4
Product keynote - introducing Magnolia 5.4
 
Launching Magnolia on demand
Launching Magnolia on demandLaunching Magnolia on demand
Launching Magnolia on demand
 
Front-end developers - build Magnolia sites faster
Front-end developers - build Magnolia sites fasterFront-end developers - build Magnolia sites faster
Front-end developers - build Magnolia sites faster
 
Magnolia and beacons: how do they work best together?
Magnolia and beacons: how do they work best together?Magnolia and beacons: how do they work best together?
Magnolia and beacons: how do they work best together?
 
Magnolia and the IOT
Magnolia and the IOTMagnolia and the IOT
Magnolia and the IOT
 
Internationalization for globalized enterprise websites
Internationalization for globalized enterprise websitesInternationalization for globalized enterprise websites
Internationalization for globalized enterprise websites
 
The new visana website how to fit a square peg into a round hole
The new visana website   how to fit a square peg into a round holeThe new visana website   how to fit a square peg into a round hole
The new visana website how to fit a square peg into a round hole
 
Solving for complex UI designs: a front-end perspective and approach
Solving for complex UI designs: a front-end perspective and approachSolving for complex UI designs: a front-end perspective and approach
Solving for complex UI designs: a front-end perspective and approach
 
Extending Magnolia with our solutions
Extending Magnolia with our solutionsExtending Magnolia with our solutions
Extending Magnolia with our solutions
 
Boost your online e commerce with magnolia
Boost your online e commerce with magnoliaBoost your online e commerce with magnolia
Boost your online e commerce with magnolia
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

Optimizing Content Managed Rich JavaScript Apps

  • 1. Optimizing Content Managed JavaScript Applications with Magnolia
  • 2. Hi, I am Adam Galloway Development Lead at NRG Edge We are from Philadelphia, PA WE ARE A BANK TECHNOLOGY SOLUTIONS & SERVICES COMPANY
  • 3. Let’s talk about Hulk Hogan
  • 4. I mean Hulk and Hogan… js
  • 5. Hogan.js • A lightweight JavaScript Mustache templating engine (2.5K) • Created by Twitter • No framework dependencies • Works great by itself but also integrates easily with Backbone.js and Marionette.js
  • 6.
  • 7. Great but… • Template markup is stored in a string? – That seems like a pain to maintain. • The string has to be compiled before rendering? – That seems like a performance concern. • This is all happens in the browser before the page can load? – That seems like a bad time to slow things down.
  • 8. Hulk enters the ring • Hulk is a node.js command line tool offered by Hogan.js • Hulk turns Mustache markup into precompiled ready-to-use JavaScript objects • It reads in markup from multiple text files with the .hogan file extension • It outputs a minified .js file that can be included in your html as a regular JavaScript file
  • 10. It’s getting better How this helps • We are no longer dealing with building strings in JavaScript • We no longer need the browser to compile anything • It combines multiple templates into one resource How this hurts • This is a command line tool • It needs node.js to run • It becomes another step in the build process • It doesn’t seem very friendly to content management
  • 11. How to make it work for us • Let’s compile the templates on the server side in Java when we can’t use node.js • Let’s do this in a servlet so we don’t have to do this only at build time • Let’s content manage the markup used in the templates
  • 12. javax.script.ScriptEngine • Java 6 includes the ScriptEngine API that allows running ECMAScript from Java • The ScriptEngine allows passing Java variables to and from the JavaScript being executed • We can use ScriptEngine in a Servlet and we can pass it InputStreams and Strings to be executed* *Thanks to a great blog post by Christian Grobmeier for precompiling Hogan.js in a Struts 2 action
  • 14. Magnolia meets Hogan • We can easily create Magnolia templates that contain Mustache markup ready to be used as a Hogan.js templates • We can easily query mgnl:components and mgnl:areas and then compile them into one resource (like Hulk does with .hogan files) • We can recompile whenever content changes and we can cache the results easily
  • 15. A very simple example.ftl Notice the Mustache and Freemarker code playing nicely together
  • 16. Now we are content managed! • We are now content managing the Hogan templates • We are now precompiling the Hogan templates • But wait there’s more! • In this servlet we can also – clean the html in the Hogan markup before we compile it – use YUI Compressor to compress the JavaScript produced by compiling – cache the cleaned compressed compiled result – gzip the response
  • 17. Ok, now I see a bunch of curly brackets • Using this .ftl in Magnolia Author you will see a lot of Mustache placeholders in the editor • Can’t we just replace the placeholders with sample data? • Yes, and because each view is mocked up on the server side we can create a Java filter to use Mustache to replace the placeholders with sample values
  • 18. Steps to put it all together 1. Take an existing .hogan template file that you would use with hulk and add it to Magnolia as an .ftl template 2. Add Freemarker code and Magnolia components needed to manage any content 3. Add a filter to show sample data in Magnolia Author 4. Add a servlet to query the content from Magnolia, precompile it using ScriptEngine and optimize it using YUI Compressor 5. Include the JavaScript returned by the servlet in our web application 6. Use the Hogan template objects just like any other Hogan template
  • 19. Let’s see a quick demo
  • 20. What about other frameworks - Handlebars • Handlebars is another commonly used Mustache templating engine • Thankfully nearly all of this code can be reused with Handlebars • Simply change the libraries used in the precompile servlet and then change the compilation code from: – Hogan.compile(templateString, {asString: true}); to: – Handlebars.precompile(templateString).toString();
  • 21. What about other frameworks – Angular.js • Angular.js actively renders templates instead of compiling and merging them with data at render time • We can still generate a single JavaScript file containing minified content managed templates • The code generated by the servlet would be similar to this:
  • 22. “I fear no man, no beast or evil, brother.” - HULK HOGAN
  • 23. And neither should we. ANY QUESTIONS?
  • 24. Sources • Rocky statue image from Wikimedia - creative commons attribution – http://wikimediafoundation.org/wiki/File:9.26.06RockyStatueByLuigiNovi1.jpg • Hulk Hogan image from flickr - creative commons attribution – http://m.flickr.com/#/photos/hodgers/3415258483/sizes/l/ • Example code using ScriptEngine from Christian Grobmeier’s blog – http://www.grobmeier.de/precompiling-hogan-jsmustache-templates-on-a-java-server-with- struts-2-16012012.html • Jsfiddle for the example Hogan.js template – http://jsfiddle.net/qDBXF/