SlideShare une entreprise Scribd logo
1  sur  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…???

Contenu connexe

Tendances

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
 

Tendances (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
 

En vedette

Git - a overview for beginners
Git - a overview for beginnersGit - a overview for beginners
Git - a overview for beginnersAnton Pirker
 
The best ways to drive your Startup into the ground
The best ways to drive your Startup into the groundThe best ways to drive your Startup into the ground
The best ways to drive your Startup into the groundAnton Pirker
 
Django user permissions in your templates
Django  user permissions  in your templatesDjango  user permissions  in your templates
Django user permissions in your templatesAnton Pirker
 
Organize your Django templates
Organize your Django templatesOrganize your Django templates
Organize your Django templatesAnton Pirker
 
Django and Nginx reverse proxy cache
Django and Nginx reverse proxy cacheDjango and Nginx reverse proxy cache
Django and Nginx reverse proxy cacheAnton Pirker
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerLuminary Labs
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsLinkedIn
 

En vedette (7)

Git - a overview for beginners
Git - a overview for beginnersGit - a overview for beginners
Git - a overview for beginners
 
The best ways to drive your Startup into the ground
The best ways to drive your Startup into the groundThe best ways to drive your Startup into the ground
The best ways to drive your Startup into the ground
 
Django user permissions in your templates
Django  user permissions  in your templatesDjango  user permissions  in your templates
Django user permissions in your templates
 
Organize your Django templates
Organize your Django templatesOrganize your Django templates
Organize your Django templates
 
Django and Nginx reverse proxy cache
Django and Nginx reverse proxy cacheDjango and Nginx reverse proxy cache
Django and Nginx reverse proxy cache
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 

Similaire à Html templating introduction

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
 

Similaire à Html templating introduction (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
 

Plus de Nagaraju Sangam

Plus de 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 - DOT JS
Html Templating - DOT JSHtml Templating - DOT JS
Html Templating - DOT JS
 
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
 

Dernier

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Dernier (20)

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Html templating introduction

  • 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