Week11 Slides
Week11 Slides
HTML Evolution
Markup languages
● Origins from late 60s
● Mostly used for typesetting and document management systems
● Problems?
○ Lack of standardization
○ Target audience: coders, publishers, academics?
○ Target output: print, other forms of media
○ Machine readability
SGML
Standard Generalized Markup Language
● Based on SGML
● Custom tags - multiple applications defined
● Focus on simplicity, generality and usability
● Both human-readable and machine-readable
● Well structured: can be used to represent complex data relationships, data structures etc.
● Examples:
○ MathML, RSS, Atom, SVG
XML Example - RSS feeds
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>RSS Title</title>
<description>This is an example of an RSS feed</description>
<link>http://www.example.com/main.html</link>
<copyright>2020 Example.com All rights reserved</copyright>
<lastBuildDate>Mon, 06 Sep 2010 00:01:00 +0000</lastBuildDate>
<pubDate>Sun, 06 Sep 2009 16:20:00 +0000</pubDate>
<ttl>1800</ttl>
<item>
<title>Example entry</title>
<description>Here is some text containing an interesting description.</description>
<link>http://www.example.com/blog/post/1</link>
<guid isPermaLink="false">7bd204c6-1655-4c27-aeee-53f933c5395f</guid>
<pubDate>Sun, 06 Sep 2009 16:20:00 +0000</pubDate>
</item>
</channel>
</rss>
XML Example: SVG
<svg version="1.1"
width="300" height="200"
xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" fill="red" />
<circle cx="150" cy="100" r="80" fill="green" />
<text x="150" y="125" font-size="60"
text-anchor="middle" fill="white">SVG</text>
</svg>
XHTML
● Based on XML - not directly SGML
● Reformulation of HTML4 as applications of XML
● Main goal: clean up HTML specification
○ Modular and more extensible
● XML Namespaces: allow inter-operability with other XML applications
HTML5
● Add support for latest features (multimedia support, canvases, …)
● Remain easily readable and understandable to both human and machine
● Remain backward compatible
● Breaks away from SGML:
○ Not an SGML or XML application
○ Defines own parser
HTML5
● Add support for latest features (multimedia support, canvases, …)
● Remain easily readable and understandable to both human and machine
● Remain backward compatible
● Breaks away from SGML:
○ Not an SGML or XML application
○ Defines own parser
Requirement? Javascript
JavaScript Lightning overview -
https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/What_is_JavaScript#i
nline_javascript_handlers
● https://developer.mozilla.org/en-US/docs/Learn/JavaScript
● https://learnjavascript.online/
Custom Elements
Adding custom elements
● XML allows arbitrary namespaces and tag definitions
○ Applications can be defined on top of XML tag definitions
● But HTML5 does not use the same approach
● Requirement for elements:
○ Meaning: what does a tag mean - <title>, <h1> etc OK, but is <my-button> actually a button?
○ Rendering: how should a tag be shown: provide display details for each tag
○ States: checkbox can be checked or blank - what about custom tags?
○ Customized built-in element or Autonomous custom element?
https://html.spec.whatwg.org/multipage/custom-elements.html
Web Components
● Custom elements
○ JS API to create custom element tags
● Shadow DOM
○ API to keep styling of component separate from rest of page
● HTML Templates
○ <template> and <slot> tags to write markup templates
Web Component Examples
● https://github.com/mdn/web-components-examples
● https://mdn.github.io/web-components-examples/editable-list/
● https://mdn.github.io/web-components-examples/edit-word/
● https://mdn.github.io/web-components-examples/word-count-web-component/
● https://css-tricks.com/an-introduction-to-web-components/
Summary
● Custom Elements: API to extend HTML5 element/tag capabilities
● Shadow DOM: restrict scope of styling or modification of content
● HTML Templates
● Goal: reuse
● Problem: limited standardization
Frameworks
Purpose of a framework
● Basic functionality already available
○ Python can create network listeners, manipulate strings etc.
○ JS can extend elements, use APIs to manipulate documents
● Problem:
○ Lots of code repetition - boilerplate
○ Reinventing the wheel - different coding styles, techniques
● Solution:
○ Standard techniques for common problems - design patterns
○ Frameworks: Flask for Python web apps, React for JS components
● SPA: Single Page Application
○ Many JS front-end frameworks focus on enabling this - also useful for mobile
Example - React
Library for building user interfaces
● Declarative
○ Opposed to imperative - specify what is needed, not how to do it
● Components
○ Different from WebComponents - similar ideas, different techniques
○ Webcomponents are more imperative: functions that specify behaviour
○ React is declarative: focus on UI, but allow composing views
● Examples: https://reactjs.org/
Frameworks
● React - numerically most popular at present
● Angular - origins from Google - well supported
● EmberJS - component + service framework
● Vue
https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_fr
ameworks/Introduction
Summary
● HTML5 is a living standard - no major changes, but continuous adaptation
● JS provides the adaptation layer
● HTML + CSS + JS = rule the world!
● But difficult to code
● Frameworks fill in the gaps