SlideShare a Scribd company logo
HTML Templating – Introduction
- Nagaraju Sangam
How many patterns you see here????
????
What?
• Template is a repeated markup from an html page
• Key is to identify and isolate the pattern.
• Bind the template with data and write to screen as html
What are the repeating elements in HTML?
 tables:
tr
td
 ul/ol
li
 select
options
 Any element can be repeated….!!!
HTML Template usecases?
 Menu Items
 Items in a cart
 Images in carousels
 Search results
 Popup dialogs
 Advertisements
 Discussions ( request/response)
 Mail items
 Records in a report
 Windows Tiles
 News Items
 Announcements
 UI Widgets
 List is huge……
World without templating?
 Templating world:
Fetch Template & data from the server, build html out of this data & template
on fly and render it on browser. Templating can be used both on server side and client
side.
Client Server
HTML
 Traditional approach:
Entire html is prepared at server side and fetched to browser for rendering.
Client Server
HTML Template
Data
Mixing the template and data...!!!
Template
(text)
Data
(JSON)
Markup
(text)
<div>
Name: <b> {{name}</b>
Phone: <b> {{phone}}</b>
Mobile: <b> {{mobile}}</b>
</div>
{
name: ‘Nagaraju,
phone: ‘080-12345’,
mobile: ‘8095410410’
}
Name: Nagaraj
Phone: 080-12345
Mobile: 8095410410
Advantages
 Separation of concerns: UI from data
 Reduce server load: Client Side processing. Templates can be loaded from CDNs.
 Low bandwidth usage: template is loaded once and cached on client.
 User Experience: Using ajax to load data and templates
 Reusability: of templates
 Flexibility : to load temaplates from CDNs/resource servers and data from
restful/soap based web services
 Many options: Number of engines available in market
 We can build offline applications: load template & data and cache it on client
Disadvantages
 Not Search Engine friendly.
 Not History friendly
How templating works?
TemplateFunction = engine.template(txtHTMLTemplate);
Markup = TemplateFunction(data);
Template
Engine
functiondata
markup
HTML Templating Engines
Underscore.js
Mustache.js
Handlebars.js
EJS.js
doT.js
jQuery
Jade.js
Knockout.js
Pure.Js
Dust.js
Swig
JUST
ECO.js
Hogan.js
Temp.js
Kendo.js
Contenmplate.js
CoffeeKup
Fest.js
Gaikan
Liquor
JUST
QEJS
Atpl
Whiskers
Walrus
Toffee
jazz
Classification
 Embedded JavaScript Vs logic-less.
More logic – more complex, but flexible
No logic – simple, but not flexible
 Client side Vs Server side
All server side templating engines can be used on client side, but not vice versa.
 DOM based Vs Text Based
 FW agnostic Vs FW built in
Things to consider for choosing a templating engines:
• Performance
• Flexibility
• Maturity
• Lightweight
• Server side/client side?
• Support and documentation.
• Package Manager Support (npm,bower etc)
• Framework Agnostic.
• Module system support(CommonJS, AMD, globals)
– http://garann.github.io/template-chooser/
– https://github.com/Deathspike/template-benchmark
– http://jsperf.com/js-template-engines-performance/95
Challenges…???
Syntax :
There is a learning curve when we adopt to a new templating engine
– Template Syntax (HAML/Jade Vs Dot/EJS)
- HTML or CoffeeScript based syntax
– Method name are different but they do the same, this has to be standardized across all 
- dot.template(), _.template(),
- swig.compile() , Hogan.compile(), dust.compile, Handlebars.compile()
- Mustache.to_html()
– Binding Syntax: <% prop %>, {{=prop}}, {prop}, {{prop}}
– Comments:
- html comments are understood by all templating engines.
- Own syntax for some templating engines ( e.g. dust: {# comments #} )
Challenges…???
Loading Templates:
- Including templates in pages (internal templates)
- script tag: <script type=“text/html” src=“url”/>
- template tag of HTML5
- Use Ajax to load template & data
- Use engine built-in feature: e.g. new EJS({url: '/template.ejs'}).render(data)
Data Binding:
- One-way/Two-way (e.g. Knockout allows both bindings)
Handling Template Inheritance:
- Master/Slave page kind of implementation
Error Handling/Debugging:
- Some templating engines properly reports errors (EJS will give error line no.)
Best Practices
• Optimize your markup for better performance.
• Separate script and styles for readability.
• Load your templates and images from CDN server.
• innerHTML can cause memory leaks, so use appendChild method.
• Use precompile templates via build system to improve performance
• Re-use DOMs instead of disposing and recreating. (cache in DomPool object)
• Manipulate Dom off the document (via document fragments)
• Preventing injections via dataContext
- Use escape() utility methods
• Do not loop thru html collections, its slower.
• Don’t leak teamplates, use CSRF token on the form to avoid XSS attacks.
• If you want to sandbox styles and dom, use WebComponents.
• Common scripts across templates should be defined outside templates under a
template utility script so the template becomes readable.
Demos…!!!
• Demo1: Client Side templating with the following engines
- EJS
- Mustache
- Handlebars
- dot.js
- dust
- Hogan
- swig
- underscore
• Demo2: Server Side Templating with Jade and Express
QA
No questions
please…???

More Related Content

What's hot (20)

PPTX
Ajax presentation
Bharat_Kumawat
 
PDF
phpWebApp presentation
Dashamir Hoxha
 
PPT
Ajax Ppt
Hema Prasanth
 
PPT
Ajax Presentation
ronaldmam
 
PPT
Ajax Ppt 1
JayaPrakash.m
 
PPT
Introduction to ajax
Venkat Pinagadi
 
ODP
Ajax Basics And Framework
shivas
 
PPT
4005-713 ` XML Architecture, Tools & Technique ` Presentation
litcigar
 
PPTX
Overview of AJAX
Roshith S Pai
 
PPT
Asynchronous JavaScript & XML (AJAX)
Adnan Sohail
 
PPTX
Ajax
Tech_MX
 
PPTX
Introduction to ajax
Pihu Goel
 
PPT
Ajax Introduction
Oliver Cai
 
PDF
Web Scraper Features – Semalt Expert
PatelSavaj
 
PDF
Introduction to ajax
Nir Elbaz
 
PPTX
Fundamentals of Web building
RC Morales
 
PDF
Intro to mobile web application development
zonathen
 
PPT
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
Ajax presentation
Bharat_Kumawat
 
phpWebApp presentation
Dashamir Hoxha
 
Ajax Ppt
Hema Prasanth
 
Ajax Presentation
ronaldmam
 
Ajax Ppt 1
JayaPrakash.m
 
Introduction to ajax
Venkat Pinagadi
 
Ajax Basics And Framework
shivas
 
4005-713 ` XML Architecture, Tools & Technique ` Presentation
litcigar
 
Overview of AJAX
Roshith S Pai
 
Asynchronous JavaScript & XML (AJAX)
Adnan Sohail
 
Ajax
Tech_MX
 
Introduction to ajax
Pihu Goel
 
Ajax Introduction
Oliver Cai
 
Web Scraper Features – Semalt Expert
PatelSavaj
 
Introduction to ajax
Nir Elbaz
 
Fundamentals of Web building
RC Morales
 
Intro to mobile web application development
zonathen
 
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 

Similar to Html Templating - DOT JS (20)

PDF
JS Single-Page Web App Essentials
Sergey Bolshchikov
 
KEY
$.Template
Dave Furfero
 
PPTX
Pearls and Must-Have Tools for the Modern Web / .NET Developer
Ofer Zelig
 
PDF
Working with Dynamic Content and Adding Templating engines, MVC
Knoldus Inc.
 
PPTX
f8db413453b33e4ffrointend development bbasics.pptx
vallabhdeshpande7499
 
PDF
Frontend Interview Questions PDF By ScholarHat
Scholarhat
 
PDF
HTML, CSS & Javascript Architecture (extended version) - Jan Kraus
Women in Technology Poland
 
PDF
Front-End Frameworks: a quick overview
Diacode
 
PDF
Having Fun Building Web Applications (Day 1 Slides)
Clarence Ngoh
 
PPTX
JavaScript front end performance optimizations
Chris Love
 
PDF
Finding harmony in web development
Christian Heilmann
 
PDF
FFWD.PRO - It's not you, It's me (or how to avoid being coupled with a Javasc...
Marco Cedaro
 
PDF
Dust.js
Yevgeniy Brikman
 
PPT
Intro to-html-backbone
zonathen
 
PDF
Building a Better Web with HTML5 and CSS3
Karambir Singh Nain
 
PDF
New Features Coming in Browsers (RIT '09)
jeresig
 
PPTX
Mobile gotcha
phegaro
 
ODP
Web program-peformance-optimization
xiaojueqq12345
 
PDF
Everything is Awesome - Cutting the Corners off the Web
James Rakich
 
JS Single-Page Web App Essentials
Sergey Bolshchikov
 
$.Template
Dave Furfero
 
Pearls and Must-Have Tools for the Modern Web / .NET Developer
Ofer Zelig
 
Working with Dynamic Content and Adding Templating engines, MVC
Knoldus Inc.
 
f8db413453b33e4ffrointend development bbasics.pptx
vallabhdeshpande7499
 
Frontend Interview Questions PDF By ScholarHat
Scholarhat
 
HTML, CSS & Javascript Architecture (extended version) - Jan Kraus
Women in Technology Poland
 
Front-End Frameworks: a quick overview
Diacode
 
Having Fun Building Web Applications (Day 1 Slides)
Clarence Ngoh
 
JavaScript front end performance optimizations
Chris Love
 
Finding harmony in web development
Christian Heilmann
 
FFWD.PRO - It's not you, It's me (or how to avoid being coupled with a Javasc...
Marco Cedaro
 
Intro to-html-backbone
zonathen
 
Building a Better Web with HTML5 and CSS3
Karambir Singh Nain
 
New Features Coming in Browsers (RIT '09)
jeresig
 
Mobile gotcha
phegaro
 
Web program-peformance-optimization
xiaojueqq12345
 
Everything is Awesome - Cutting the Corners off the Web
James Rakich
 
Ad

More from Nagaraju Sangam (6)

PPTX
Angular js 2.0 beta
Nagaraju Sangam
 
PPTX
Ng quick
Nagaraju Sangam
 
PPTX
Introduction to Angular js 2.0
Nagaraju Sangam
 
PPTX
Html templating introduction
Nagaraju Sangam
 
PDF
Developing apps for humans & robots
Nagaraju Sangam
 
PDF
Introduction to jQuery
Nagaraju Sangam
 
Angular js 2.0 beta
Nagaraju Sangam
 
Ng quick
Nagaraju Sangam
 
Introduction to Angular js 2.0
Nagaraju Sangam
 
Html templating introduction
Nagaraju Sangam
 
Developing apps for humans & robots
Nagaraju Sangam
 
Introduction to jQuery
Nagaraju Sangam
 
Ad

Recently uploaded (20)

PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 

Html Templating - DOT JS

  • 1. HTML Templating – Introduction - Nagaraju Sangam
  • 2. How many patterns you see here????
  • 4. What? • Template is a repeated markup from an html page • Key is to identify and isolate the pattern. • Bind the template with data and write to screen as html
  • 5. What are the repeating elements in HTML?  tables: tr td  ul/ol li  select options  Any element can be repeated….!!!
  • 6. HTML Template usecases?  Menu Items  Items in a cart  Images in carousels  Search results  Popup dialogs  Advertisements  Discussions ( request/response)  Mail items  Records in a report  Windows Tiles  News Items  Announcements  UI Widgets  List is huge……
  • 7. World without templating?  Templating world: Fetch Template & data from the server, build html out of this data & template on fly and render it on browser. Templating can be used both on server side and client side. Client Server HTML  Traditional approach: Entire html is prepared at server side and fetched to browser for rendering. Client Server HTML Template Data
  • 8. Mixing the template and data...!!! Template (text) Data (JSON) Markup (text) <div> Name: <b> {{name}</b> Phone: <b> {{phone}}</b> Mobile: <b> {{mobile}}</b> </div> { name: ‘Nagaraju, phone: ‘080-12345’, mobile: ‘8095410410’ } Name: Nagaraj Phone: 080-12345 Mobile: 8095410410
  • 9. Advantages  Separation of concerns: UI from data  Reduce server load: Client Side processing. Templates can be loaded from CDNs.  Low bandwidth usage: template is loaded once and cached on client.  User Experience: Using ajax to load data and templates  Reusability: of templates  Flexibility : to load temaplates from CDNs/resource servers and data from restful/soap based web services  Many options: Number of engines available in market  We can build offline applications: load template & data and cache it on client
  • 10. Disadvantages  Not Search Engine friendly.  Not History friendly
  • 11. How templating works? TemplateFunction = engine.template(txtHTMLTemplate); Markup = TemplateFunction(data); Template Engine functiondata markup
  • 13. Classification  Embedded JavaScript Vs logic-less. More logic – more complex, but flexible No logic – simple, but not flexible  Client side Vs Server side All server side templating engines can be used on client side, but not vice versa.  DOM based Vs Text Based  FW agnostic Vs FW built in
  • 14. Things to consider for choosing a templating engines: • Performance • Flexibility • Maturity • Lightweight • Server side/client side? • Support and documentation. • Package Manager Support (npm,bower etc) • Framework Agnostic. • Module system support(CommonJS, AMD, globals) – http://garann.github.io/template-chooser/ – https://github.com/Deathspike/template-benchmark – http://jsperf.com/js-template-engines-performance/95
  • 15. Challenges…??? Syntax : There is a learning curve when we adopt to a new templating engine – Template Syntax (HAML/Jade Vs Dot/EJS) - HTML or CoffeeScript based syntax – Method name are different but they do the same, this has to be standardized across all  - dot.template(), _.template(), - swig.compile() , Hogan.compile(), dust.compile, Handlebars.compile() - Mustache.to_html() – Binding Syntax: <% prop %>, {{=prop}}, {prop}, {{prop}} – Comments: - html comments are understood by all templating engines. - Own syntax for some templating engines ( e.g. dust: {# comments #} )
  • 16. Challenges…??? Loading Templates: - Including templates in pages (internal templates) - script tag: <script type=“text/html” src=“url”/> - template tag of HTML5 - Use Ajax to load template & data - Use engine built-in feature: e.g. new EJS({url: '/template.ejs'}).render(data) Data Binding: - One-way/Two-way (e.g. Knockout allows both bindings) Handling Template Inheritance: - Master/Slave page kind of implementation Error Handling/Debugging: - Some templating engines properly reports errors (EJS will give error line no.)
  • 17. Best Practices • Optimize your markup for better performance. • Separate script and styles for readability. • Load your templates and images from CDN server. • innerHTML can cause memory leaks, so use appendChild method. • Use precompile templates via build system to improve performance • Re-use DOMs instead of disposing and recreating. (cache in DomPool object) • Manipulate Dom off the document (via document fragments) • Preventing injections via dataContext - Use escape() utility methods • Do not loop thru html collections, its slower. • Don’t leak teamplates, use CSRF token on the form to avoid XSS attacks. • If you want to sandbox styles and dom, use WebComponents. • Common scripts across templates should be defined outside templates under a template utility script so the template becomes readable.
  • 18. Demos…!!! • Demo1: Client Side templating with the following engines - EJS - Mustache - Handlebars - dot.js - dust - Hogan - swig - underscore • Demo2: Server Side Templating with Jade and Express