SlideShare a Scribd company logo
1 of 19
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

phpWebApp presentation
phpWebApp presentationphpWebApp presentation
phpWebApp presentationDashamir Hoxha
 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentationronaldmam
 
Ajax Basics And Framework
Ajax Basics And FrameworkAjax Basics And Framework
Ajax Basics And Frameworkshivas
 
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 ` Presentationlitcigar
 
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 ajaxPihu Goel
 
Ajax Introduction
Ajax IntroductionAjax Introduction
Ajax IntroductionOliver Cai
 
Web Scraper Features – Semalt Expert
Web Scraper Features – Semalt ExpertWeb Scraper Features – Semalt Expert
Web Scraper Features – Semalt ExpertPatelSavaj
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajaxNir Elbaz
 
Fundamentals of Web building
Fundamentals of Web buildingFundamentals of Web building
Fundamentals of Web buildingRC Morales
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application developmentzonathen
 

What's hot (20)

Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
 
phpWebApp presentation
phpWebApp presentationphpWebApp presentation
phpWebApp presentation
 
Ajax Ppt
Ajax PptAjax Ppt
Ajax Ppt
 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentation
 
Ajax Ppt 1
Ajax Ppt 1Ajax Ppt 1
Ajax Ppt 1
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Ajax.ppt
Ajax.pptAjax.ppt
Ajax.ppt
 
Ajax ppt
Ajax pptAjax ppt
Ajax ppt
 
Ajax Basics And Framework
Ajax Basics And FrameworkAjax Basics And Framework
Ajax Basics And Framework
 
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
 
Overview of AJAX
Overview of AJAXOverview of AJAX
Overview of AJAX
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
 
Ajax
AjaxAjax
Ajax
 
Introduction to ajax
Introduction  to  ajaxIntroduction  to  ajax
Introduction to ajax
 
Ajax Introduction
Ajax IntroductionAjax Introduction
Ajax Introduction
 
Web Scraper Features – Semalt Expert
Web Scraper Features – Semalt ExpertWeb Scraper Features – Semalt Expert
Web Scraper Features – Semalt Expert
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Fundamentals of Web building
Fundamentals of Web buildingFundamentals of Web building
Fundamentals of Web building
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application development
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 

Similar to Html Templating - DOT JS

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 introductionMichael Ahearn
 
Intro to-html-backbone
Intro to-html-backboneIntro to-html-backbone
Intro to-html-backbonezonathen
 
MCA-202-W4-L1.pptx
MCA-202-W4-L1.pptxMCA-202-W4-L1.pptx
MCA-202-W4-L1.pptxmanju451965
 
Building high performing web pages
Building high performing web pagesBuilding high performing web pages
Building high performing web pagesNilesh Bafna
 
Innovate2011 Keys to Building OSLC Integrations
Innovate2011 Keys to Building OSLC IntegrationsInnovate2011 Keys to Building OSLC Integrations
Innovate2011 Keys to Building OSLC IntegrationsSteve 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 servershivanichourasia01
 
Web Development Today
Web Development TodayWeb Development Today
Web Development Todaybretticus
 
wd project.pptx
wd project.pptxwd project.pptx
wd project.pptxdsffsdf1
 
Architecting single-page front-end apps
Architecting single-page front-end appsArchitecting single-page front-end apps
Architecting single-page front-end appsZohar Arad
 
Web performance essentials - Goodies
Web performance essentials - GoodiesWeb performance essentials - Goodies
Web performance essentials - GoodiesJerry Emmanuel
 
Decoding the Web
Decoding the WebDecoding the Web
Decoding the Webnewcircle
 
C# Advanced L09-HTML5+ASP
C# Advanced L09-HTML5+ASPC# Advanced L09-HTML5+ASP
C# Advanced L09-HTML5+ASPMohammad 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 NetAdil Mughal
 
BITM3730Week12.pptx
BITM3730Week12.pptxBITM3730Week12.pptx
BITM3730Week12.pptxMattMarino13
 
黑豹 ch4 ddd pattern practice (2)
黑豹 ch4 ddd pattern practice (2)黑豹 ch4 ddd pattern practice (2)
黑豹 ch4 ddd pattern practice (2)Fong Liou
 
Html & CSS - Best practices 2-hour-workshop
Html & CSS - Best practices 2-hour-workshopHtml & CSS - Best practices 2-hour-workshop
Html & CSS - Best practices 2-hour-workshopVero Rebagliatte
 

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
 
Intro to-html-backbone
Intro to-html-backboneIntro to-html-backbone
Intro to-html-backbone
 
PPT
PPTPPT
PPT
 
MCA-202-W4-L1.pptx
MCA-202-W4-L1.pptxMCA-202-W4-L1.pptx
MCA-202-W4-L1.pptx
 
Building high performing web pages
Building high performing web pagesBuilding high performing web pages
Building high performing web pages
 
Web Programming introduction
Web Programming introductionWeb Programming introduction
Web Programming introduction
 
Innovate2011 Keys to Building OSLC Integrations
Innovate2011 Keys to Building OSLC IntegrationsInnovate2011 Keys to Building OSLC Integrations
Innovate2011 Keys to Building OSLC Integrations
 
Overview of PHP and MYSQL
Overview of PHP and MYSQLOverview of PHP and MYSQL
Overview of PHP and MYSQL
 
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
 
Web Development Today
Web Development TodayWeb Development Today
Web Development Today
 
wd project.pptx
wd project.pptxwd project.pptx
wd project.pptx
 
Architecting single-page front-end apps
Architecting single-page front-end appsArchitecting single-page front-end apps
Architecting single-page front-end apps
 
Web performance essentials - Goodies
Web performance essentials - GoodiesWeb performance essentials - Goodies
Web performance essentials - Goodies
 
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
 
Decoding the Web
Decoding the WebDecoding the Web
Decoding the Web
 
C# Advanced L09-HTML5+ASP
C# Advanced L09-HTML5+ASPC# Advanced L09-HTML5+ASP
C# Advanced L09-HTML5+ASP
 
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
 
BITM3730Week12.pptx
BITM3730Week12.pptxBITM3730Week12.pptx
BITM3730Week12.pptx
 
黑豹 ch4 ddd pattern practice (2)
黑豹 ch4 ddd pattern practice (2)黑豹 ch4 ddd pattern practice (2)
黑豹 ch4 ddd pattern practice (2)
 
Html & CSS - Best practices 2-hour-workshop
Html & CSS - Best practices 2-hour-workshopHtml & CSS - Best practices 2-hour-workshop
Html & CSS - Best practices 2-hour-workshop
 

More from Nagaraju Sangam

More from Nagaraju Sangam (6)

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

Recently uploaded

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
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...Martijn de Jong
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
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 2024The Digital Insurer
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
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 WorkerThousandEyes
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 

Recently uploaded (20)

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].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...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
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
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 

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