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…???
Ad

More Related Content

What's hot (20)

Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
Bharat_Kumawat
 
phpWebApp presentation
phpWebApp presentationphpWebApp presentation
phpWebApp presentation
Dashamir Hoxha
 
Ajax Ppt
Ajax PptAjax Ppt
Ajax Ppt
Hema Prasanth
 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentation
ronaldmam
 
Ajax Ppt 1
Ajax Ppt 1Ajax Ppt 1
Ajax Ppt 1
JayaPrakash.m
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
Venkat Pinagadi
 
Ajax.ppt
Ajax.pptAjax.ppt
Ajax.ppt
MAGNA COLLEGE OF ENGINEERING
 
Ajax ppt
Ajax pptAjax ppt
Ajax ppt
OECLIB Odisha Electronics Control Library
 
Ajax Basics And Framework
Ajax Basics And FrameworkAjax Basics And Framework
Ajax Basics And Framework
shivas
 
4005-713 ` XML Architecture, Tools & Technique ` Presentation
4005-713 ` XML Architecture, Tools & Technique ` Presentation4005-713 ` XML Architecture, Tools & Technique ` Presentation
4005-713 ` XML Architecture, Tools & Technique ` Presentation
litcigar
 
Overview of AJAX
Overview of AJAXOverview of AJAX
Overview of AJAX
Roshith S Pai
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
Adnan Sohail
 
Ajax
AjaxAjax
Ajax
Tech_MX
 
Introduction to ajax
Introduction  to  ajaxIntroduction  to  ajax
Introduction to ajax
Pihu Goel
 
Ajax Introduction
Ajax IntroductionAjax Introduction
Ajax Introduction
Oliver Cai
 
Web Scraper Features – Semalt Expert
Web Scraper Features – Semalt ExpertWeb Scraper Features – Semalt Expert
Web Scraper Features – Semalt Expert
PatelSavaj
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
Nir Elbaz
 
Fundamentals of Web building
Fundamentals of Web buildingFundamentals of Web building
Fundamentals of Web building
RC Morales
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application development
zonathen
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
phpWebApp presentation
phpWebApp presentationphpWebApp presentation
phpWebApp presentation
Dashamir Hoxha
 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentation
ronaldmam
 
Ajax Basics And Framework
Ajax Basics And FrameworkAjax Basics And Framework
Ajax Basics And Framework
shivas
 
4005-713 ` XML Architecture, Tools & Technique ` Presentation
4005-713 ` XML Architecture, Tools & Technique ` Presentation4005-713 ` XML Architecture, Tools & Technique ` Presentation
4005-713 ` XML Architecture, Tools & Technique ` Presentation
litcigar
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
Adnan Sohail
 
Introduction to ajax
Introduction  to  ajaxIntroduction  to  ajax
Introduction to ajax
Pihu Goel
 
Ajax Introduction
Ajax IntroductionAjax Introduction
Ajax Introduction
Oliver Cai
 
Web Scraper Features – Semalt Expert
Web Scraper Features – Semalt ExpertWeb Scraper Features – Semalt Expert
Web Scraper Features – Semalt Expert
PatelSavaj
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
Nir Elbaz
 
Fundamentals of Web building
Fundamentals of Web buildingFundamentals of Web building
Fundamentals of Web building
RC Morales
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application development
zonathen
 

Similar to Html Templating - DOT JS (20)

State of modern web technologies: an introduction
State of modern web technologies: an introductionState of modern web technologies: an introduction
State of modern web technologies: an introduction
Michael Ahearn
 
Intro to-html-backbone
Intro to-html-backboneIntro to-html-backbone
Intro to-html-backbone
zonathen
 
PPT
PPTPPT
PPT
webhostingguy
 
MCA-202-W4-L1.pptx
MCA-202-W4-L1.pptxMCA-202-W4-L1.pptx
MCA-202-W4-L1.pptx
manju451965
 
document object model in web technologies notes for engineering.pptx
document object model in web technologies notes for engineering.pptxdocument object model in web technologies notes for engineering.pptx
document object model in web technologies notes for engineering.pptx
manju451965
 
Building high performing web pages
Building high performing web pagesBuilding high performing web pages
Building high performing web pages
Nilesh Bafna
 
Tech Winter Break - GDG on Campus - PIET
Tech Winter Break - GDG on Campus - PIETTech Winter Break - GDG on Campus - PIET
Tech Winter Break - GDG on Campus - PIET
khushi15250705
 
Introduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptxIntroduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptx
wowiw65045
 
Web Programming introduction
Web Programming introductionWeb Programming introduction
Web Programming introduction
Abdul-Rahman Mahmood
 
Innovate2011 Keys to Building OSLC Integrations
Innovate2011 Keys to Building OSLC IntegrationsInnovate2011 Keys to Building OSLC Integrations
Innovate2011 Keys to Building OSLC Integrations
Steve Speicher
 
Overview of PHP and MYSQL
Overview of PHP and MYSQLOverview of PHP and MYSQL
Overview of PHP and MYSQL
Deblina Chowdhury
 
PPT on javascript ajax and css and some points related to server
PPT on javascript ajax and css and some points related to serverPPT on javascript ajax and css and some points related to server
PPT on javascript ajax and css and some points related to server
shivanichourasia01
 
Web Development Today
Web Development TodayWeb Development Today
Web Development Today
bretticus
 
wd project.pptx
wd project.pptxwd project.pptx
wd project.pptx
dsffsdf1
 
Architecting single-page front-end apps
Architecting single-page front-end appsArchitecting single-page front-end apps
Architecting single-page front-end apps
Zohar Arad
 
Web performance essentials - Goodies
Web performance essentials - GoodiesWeb performance essentials - Goodies
Web performance essentials - Goodies
Jerry Emmanuel
 
HTML literals, the JSX of the platform
HTML literals, the JSX of the platformHTML literals, the JSX of the platform
HTML literals, the JSX of the platform
Kenneth Rohde Christiansen
 
Decoding the Web
Decoding the WebDecoding the Web
Decoding the Web
newcircle
 
C# Advanced L09-HTML5+ASP
C# Advanced L09-HTML5+ASPC# Advanced L09-HTML5+ASP
C# Advanced L09-HTML5+ASP
Mohammad Shaker
 
DevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp NetDevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp Net
Adil Mughal
 
State of modern web technologies: an introduction
State of modern web technologies: an introductionState of modern web technologies: an introduction
State of modern web technologies: an introduction
Michael Ahearn
 
Intro to-html-backbone
Intro to-html-backboneIntro to-html-backbone
Intro to-html-backbone
zonathen
 
MCA-202-W4-L1.pptx
MCA-202-W4-L1.pptxMCA-202-W4-L1.pptx
MCA-202-W4-L1.pptx
manju451965
 
document object model in web technologies notes for engineering.pptx
document object model in web technologies notes for engineering.pptxdocument object model in web technologies notes for engineering.pptx
document object model in web technologies notes for engineering.pptx
manju451965
 
Building high performing web pages
Building high performing web pagesBuilding high performing web pages
Building high performing web pages
Nilesh Bafna
 
Tech Winter Break - GDG on Campus - PIET
Tech Winter Break - GDG on Campus - PIETTech Winter Break - GDG on Campus - PIET
Tech Winter Break - GDG on Campus - PIET
khushi15250705
 
Introduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptxIntroduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptx
wowiw65045
 
Innovate2011 Keys to Building OSLC Integrations
Innovate2011 Keys to Building OSLC IntegrationsInnovate2011 Keys to Building OSLC Integrations
Innovate2011 Keys to Building OSLC Integrations
Steve Speicher
 
PPT on javascript ajax and css and some points related to server
PPT on javascript ajax and css and some points related to serverPPT on javascript ajax and css and some points related to server
PPT on javascript ajax and css and some points related to server
shivanichourasia01
 
Web Development Today
Web Development TodayWeb Development Today
Web Development Today
bretticus
 
wd project.pptx
wd project.pptxwd project.pptx
wd project.pptx
dsffsdf1
 
Architecting single-page front-end apps
Architecting single-page front-end appsArchitecting single-page front-end apps
Architecting single-page front-end apps
Zohar Arad
 
Web performance essentials - Goodies
Web performance essentials - GoodiesWeb performance essentials - Goodies
Web performance essentials - Goodies
Jerry Emmanuel
 
Decoding the Web
Decoding the WebDecoding the Web
Decoding the Web
newcircle
 
C# Advanced L09-HTML5+ASP
C# Advanced L09-HTML5+ASPC# Advanced L09-HTML5+ASP
C# Advanced L09-HTML5+ASP
Mohammad Shaker
 
DevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp NetDevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp Net
Adil Mughal
 
Ad

More from Nagaraju Sangam (6)

Angular js 2.0 beta
Angular js 2.0 betaAngular js 2.0 beta
Angular js 2.0 beta
Nagaraju Sangam
 
Ng quick
Ng quickNg quick
Ng quick
Nagaraju Sangam
 
Introduction to Angular js 2.0
Introduction to Angular js 2.0Introduction to Angular js 2.0
Introduction to Angular js 2.0
Nagaraju Sangam
 
Html templating introduction
Html templating introductionHtml templating introduction
Html templating introduction
Nagaraju Sangam
 
Developing apps for humans & robots
Developing apps for humans & robotsDeveloping apps for humans & robots
Developing apps for humans & robots
Nagaraju Sangam
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Nagaraju Sangam
 
Ad

Recently uploaded (20)

Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Mastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdfMastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdf
Spiral Mantra
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Mastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdfMastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdf
Spiral Mantra
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 

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