SlideShare uma empresa Scribd logo
1 de 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/

Mais conteúdo relacionado

Mais procurados

Angular on ASP.NET MVC 6
Angular on ASP.NET MVC 6Angular on ASP.NET MVC 6
Angular on ASP.NET MVC 6Noam Kfir
 
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 playerTikal Knowledge
 
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 2Mindfire Solutions
 
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 worldAssaf Gannon
 
Front-End Tools and Workflows
Front-End Tools and WorkflowsFront-End Tools and Workflows
Front-End Tools and WorkflowsSara Vieira
 
Building rest services using aspnetwebapi
Building rest services using aspnetwebapiBuilding rest services using aspnetwebapi
Building rest services using aspnetwebapiBrij Mishra
 
Fastest to Mobile with Scalatra + Swagger
Fastest to Mobile with Scalatra + SwaggerFastest to Mobile with Scalatra + Swagger
Fastest to Mobile with Scalatra + SwaggerTony Tam
 
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 UniversitySyed Shanu
 
EXPERTALKS: Jul 2012 - Build using Gradle
EXPERTALKS: Jul 2012 - Build using GradleEXPERTALKS: Jul 2012 - Build using Gradle
EXPERTALKS: Jul 2012 - Build using GradleEXPERTALKS
 
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 BootOmri Spector
 
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 MvcDaniel Gradecak
 
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 2009Dr Nic Williams
 
MVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative WebtechnologieMVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative WebtechnologieOPEN KNOWLEDGE GmbH
 
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 FRAMEWORKSpringPeople
 
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 ScalePhil Leggetter
 
Why use Go for web development?
Why use Go for web development?Why use Go for web development?
Why use Go for web development?Weng Wei
 

Mais procurados (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?
 

Semelhante a Optimizing Content Managed Rich JavaScript Apps

Instagram filters (8 24)
Instagram filters (8 24)Instagram filters (8 24)
Instagram filters (8 24)Ivy Rueb
 
Instagram filters (8 24)
Instagram filters (8 24)Instagram filters (8 24)
Instagram filters (8 24)Ivy Rueb
 
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...Paul Jensen
 
Web development today
Web development todayWeb development today
Web development todayJaydev Gajera
 
Instagram filters
Instagram filters Instagram filters
Instagram filters Thinkful
 
Lightning web components
Lightning web components Lightning web components
Lightning web components Cloud Analogy
 
Untangling spring week11
Untangling spring week11Untangling spring week11
Untangling spring week11Derek Jacoby
 
Swagger - Making REST APIs friendlier
Swagger - Making REST APIs friendlierSwagger - Making REST APIs friendlier
Swagger - Making REST APIs friendlierMiroslav Resetar
 
Introduction to Grails 2013
Introduction to Grails 2013Introduction to Grails 2013
Introduction to Grails 2013Gavin Hogan
 
Modern websites in 2020 and Joomla
Modern websites in 2020 and JoomlaModern websites in 2020 and Joomla
Modern websites in 2020 and JoomlaGeorge Wilson
 
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 PostgreSQLKonstantin Gredeskoul
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scriptsch samaram
 
javascript 1
javascript 1javascript 1
javascript 1osman do
 
Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework Yakov Fain
 

Semelhante a 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
 

Mais de Magnolia

The SEO Workflow
The SEO WorkflowThe SEO Workflow
The SEO WorkflowMagnolia
 
Magnolia 6 release walkthrough
Magnolia 6 release walkthroughMagnolia 6 release walkthrough
Magnolia 6 release walkthroughMagnolia
 
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 headlessMagnolia
 
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 efficientlyMagnolia
 
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 ExperienceMagnolia
 
Customer Engagement in the Digital Era
Customer Engagement in the Digital EraCustomer Engagement in the Digital Era
Customer Engagement in the Digital EraMagnolia
 
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 BusinessMagnolia
 
Using Magnolia in a Microservices Architecture
Using Magnolia in a Microservices ArchitectureUsing Magnolia in a Microservices Architecture
Using Magnolia in a Microservices ArchitectureMagnolia
 
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 AtlassianMagnolia
 
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 keynoteMagnolia
 
Product keynote - introducing Magnolia 5.4
Product keynote - introducing Magnolia 5.4Product keynote - introducing Magnolia 5.4
Product keynote - introducing Magnolia 5.4Magnolia
 
Launching Magnolia on demand
Launching Magnolia on demandLaunching Magnolia on demand
Launching Magnolia on demandMagnolia
 
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 fasterMagnolia
 
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
 
Magnolia and the IOT
Magnolia and the IOTMagnolia and the IOT
Magnolia and the IOTMagnolia
 
Internationalization for globalized enterprise websites
Internationalization for globalized enterprise websitesInternationalization for globalized enterprise websites
Internationalization for globalized enterprise websitesMagnolia
 
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 holeMagnolia
 
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 approachMagnolia
 
Extending Magnolia with our solutions
Extending Magnolia with our solutionsExtending Magnolia with our solutions
Extending Magnolia with our solutionsMagnolia
 
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 magnoliaMagnolia
 

Mais 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
 

Último

Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 

Último (20)

Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 

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/