Text:
"Link text"
DOMDocumentObjectModel
document
Attribute:
href
Root element:
Regular DOM, Virtual DOM,
Shadow DOM & AOM
Document Object Models
Window
Document
Element
Element
Element
Element
Regular DOM
Browsers use internal representation of DOM model
Elements are nodes -> Programming languages interact
with it
HTML uses extended DOM called HTML DOM, that provides
additional API
Access to and control of HTML elements via the DOM
Access to and manipulation of form data
Supporting and connective interfaces for other APIs
...many more
Bound to displayed content on the website
const paragraphs = document.querySelectorAll("p");
// paragraphs[0] is the first element
// paragraphs[1] is the second
element, etc.
alert(paragraphs[0].nodeName);
Virtual DOM
Abstraction over the HTML DOM
Unlike Regular DOM, Virtual is not connected to the HTML
DOM
Updates only relevant nodes (Reconciliation) ->
optimised and accelared process
Minimises update operations
Diffing algorithm (diffs HTML DOM tree and Virtual DOM
tree)
Reduces O(n3) tree compare down to O(n)
Used by frameworks Vue.js, React.js...
const root = React.createElement('div');
ReactDOM.render(root, document.getElementById('example'))
Shadow DOM
Used for encapsulated web components
Keeps behaviour, markup and style separate from other code
Consists of:
Shadow host - The regular DOM node that shadow DOM is attached to
Shadow tree - The dom inside of shadow DOM
Shadow boundary - Boundary between Shadow tree and Regular Tree
Shadow root - Root node of shadow tree
Example elements having shadow DOM: video, web components
/* Attach shadow dom to element */
let shadow = elementRef.attachShadow({mode: 'open'});
/* Interact with shadow dom */
let para = document.createElement('p');
shadow.appendChild(para);
shadow
root
document
shadow
host
Document Tree
ShadowBoundary
Shadow Tree
document
shadow
host
Flattened Tree (for rendering)
Shadow
Tree
AOM DOM
Currently just a draft from 23th June of 2021 (backed by Google, Apple and Mozilla)
Aims to improve accesibility for assistive technologies
Browser rendering
Browser fetches the HTML file
HTML is parsed to HTML DOM tree
CSS is parsed into CSSOM tree
CSSOM tree and HTML DOM tree
are combined to render tree
Layout computes exact positions
and sizes of elements
Browser creates the layers of
elements
During rasterization missing
parts such as background
color, shadows are filled in
Layers are painted by the browser
on the screen
This is called Critical rendering path
Minification, Compression
Techniques used to optimise fetching process from the web-server
Minification
Process of removing all unnecessary characters (whitespaces)
Replaces variables, function names with shorter naming
Reduces size of source files (css,js,html)
Mainly for all the website text resources
Implemented by web developers
function a(){return Math.floor(6*Math.random())+1}function b(){return new c.Promise(function(a,b){var c=Math.floor(6*Math.random())+1
Compression
Increases the perfomance of the website
Implemented on browsers/clients and servers
Loss-less compression - data is not altered, matches byte to byte with original
Loosy - original data is altered
Offically used: gzip, brotli
Resources
HTML5 Tutorial on TutorialRepublic.com
https://dev.opera.com/articles/introduction-to-wai-aria/
https://wicg.github.io/aom/spec/
https://developer.mozilla.org/en-US/docs/Web/Performance/Critical_rendering_path
https://medium.com/jspoint/how-the-browser-renders-a-web-page-dom-cssom-and-rendering-
df10531c9969
https://shortdiv.com/posts/aom-at-me-bro/
https://reactjs.org/docs/reconciliation.html
https://developers.google.com/web/fundamentals/performance/critical-rendering-path/render-tree-
construction
https://developer.mozilla.org/en-US/docs/Web/Performance/Critical_rendering_path