KEMBAR78
Html css workshop, lesson 0, how browsers work | PDF
INTRODUCTION TO FRONT END WEB DEVELOPMENT
INDEX
How browsers work
Level 1: HTML
Level 2: CSS
Level 3: Layouts
Level 4: Advanced HTML
Level 5: CSS Ninja
Level 6: JavaScript Beginner
OBJECTIVE
A complete page, using Bootstrap, no JavaScript
INTRODUCTION TO FRONT END WEB DEVELOPMENT
0) HOW BROWSERS WORK
MAIN DESKTOP BROWSERS
MAIN MOBILE BROWSERS
OTHER BROWSERS
BROWSER COMPONENTS
1. The user interface
2. The browser engine
3. The rendering engine
4. Networking
5. UI backend
6. JavaScript interpreter.
7. Data storage.
BROWSER COMPONENTS
3. The rendering engine
1. The user interface
2. The browser engine
4. Networking
5. UI backend
6. JavaScript interpreter.
7. Data storage.
THE RENDERING ENGINE FLOW
PAGE.HTML
<!DOCTYPE html>
<html>
<head>
<link href="style.css" rel="stylesheet">
<title>Title</title>
</head>
<body>
<p>Hello <span>world!</span></p>
<div>
<img src="photo.jpg">
</div>
</body>
</html>
STYLE.CSS
body {
font-size: 16px;
}
p {
font-weight: bold;
}
p span {
display: none;
}
img {
float: right;
}
1) PROCESS HTML MARKUP AND BUILD THE DOM TREE
1) PROCESS HTML MARKUP AND BUILD THE DOM TREE
1. The browser sends a request to the server and reads the
raw bytes of the HTML file.
20 20 20 20 26 6c 74 3b 21 44 4f 43 54 59 50 45 20 68 74 6d
6c 3e 20 20 20 20 20 20 26 6c 74 3b 68 74 6d 6c 3e 20 20 20 20 20 20
26 6c 74 3b 68 65 61 64 3e 20 20 20 20 68 72 65 66 3d 5c 22 73 74 79
6c 65 2e 63 73 73 5c 22 20 72 65 6c 3d 5c 22 73 74 79 6c 65 73 68 65
65 74 5c 22 3e 20 20 20 20 20 20 3c
1) PROCESS HTML MARKUP AND BUILD THE DOM TREE
2. it translates them to individual characters based on
specified encoding of the file (e.g. UTF-8).
1. The browser sends a request to the server and reads the
raw bytes of the HTML file.
<html><head>...</head><body><p>Hello <span>world!</span></p
></body>...
1) PROCESS HTML MARKUP AND BUILD THE DOM TREE
3. it converts strings of characters into distinct tokens
specified by the W3C HTML5 standard - e.g. <html>,
<body>.
1. The browser sends a request to the server and reads the
raw bytes of the HTML file.
2. it translates them to individual characters based on
specified encoding of the file (e.g. UTF-8).
1) PROCESS HTML MARKUP AND BUILD THE DOM TREE
4. it converts the tokens into objects which define their
properties and rules.
1. The browser sends a request to the server and reads the
raw bytes of the HTML file.
2. it translates them to individual characters based on
specified encoding of the file (e.g. UTF-8).
3. it converts strings of characters into distinct tokens
specified by the W3C HTML5 standard - e.g. <html>,
<body>.
1) PROCESS HTML MARKUP AND BUILD THE DOM TREE
5. it links the created objects in a tree data structure that
also captures the parent-child relationships defined in the
original markup.
The DOM tree is created.
1. The browser sends a request to the server and reads the
raw bytes of the HTML file.
2. it translates them to individual characters based on
specified encoding of the file (e.g. UTF-8).
3. it converts strings of characters into distinct tokens
specified by the W3C HTML5 standard - e.g. <html>,
<body>.
4. it converts the tokens into objects which define their
properties and rules.
THE DOCUMENT OBJECT MODEL TREE
It is the object presentation of the HTML document and the interface of HTML
elements to the outside world, e.g. JavaScript.
1) PROCESS HTML MARKUP AND BUILD THE DOM TREE
The browser builds up the DOM incrementally.
The root of the tree is the Document object.
HTML is quite forgiving by nature, almost one to one
relation to the markup.
CSS, images and scripts are downloaded as soon as
possible by the HTML parser.
JavaScript execution blocks on CSSOM, scripts should go
at the end of the page and CSS at the top or inline.
JavaScript blocks DOM construction unless explicitly
declared as async.
CURRENT OUTPUT
2)PROCESS CSS MARKUP AND BUILD THE CSSOM TREE
2)PROCESS CSS MARKUP AND BUILD THE CSSOM TREE
THE CSSOM TREE
2)PROCESS CSS MARKUP AND BUILD THE CSSOM TREE
The CSSOM cannot be built incrementally like the DOM.
DOM and CSSOM are independent data structures.
By default, CSS is treated as a render blocking resource.
All CSS resources, regardless of blocking or non-blocking
behavior, are downloaded and combined.
Complexity around matching rules.
More nesting in the CSS affects performance, we need to
optimize selectors.
CURRENT OUTPUT
3)COMBINE THE DOM AND CSSOM INTO A RENDER TREE
3)COMBINE THE DOM AND CSSOM INTO A RENDER TREE
DOM tree CSSOM tree
3)COMBINE THE DOM AND CSSOM INTO A RENDER TREE
3)COMBINE THE DOM AND CSSOM INTO A RENDER TREE
It is the visual rapresentation of the document.
It enables the browser to paint elements in the screen in
the right order.
Each element in the tree is called renderer or render-
object or frame.
A renderer knows how to layout and paint itself and it's
children.
A renderer represents a rectangular area and contains
geometric informations such as width, height, position.
Every DOM element has a reference to the node in the
render tree.
Elements with display:none; or head tags are in the DOM
but not in the render tree. Not one to one with the DOM.
CURRENT OUTPUT
4) RUN LAYOUT ON THE RENDER TREE TO COMPUTE GEOMETRY OF EACH NODE
4) RUN LAYOUT ON THE RENDER TREE TO COMPUTE GEOMETRY OF EACH NODE
The browser begins at the root of the render tree and
traverses it to compute the geometry of each object on the
page.
This stage is also known as reflow.
When the changes affect the document contents or
structure, or an element position, a reflow (or relayout)
happens.
When changing element styles which don't affect the
element's position on a page (such as background-color,
border-color, visibility), a repaint happens.
Batch changes, intelligent reflow.
Reflow only dirty trees in the tree.
Accessing certain properties, e.g. with JS will immediately
reflow.
4) RUN LAYOUT ON THE RENDER TREE TO COMPUTE GEOMETRY OF EACH NODE
<html>
<head>
<title>Layout example</title>
</head>
<body>
<div style="width: 50%">
<div style="width: 50%">Hello!</div>
</div>
</body>
</html>
4) RUN LAYOUT ON THE RENDER TREE TO COMPUTE GEOMETRY OF EACH NODE
REFLOW IN SLOW-MOTION
1:22
CURRENT OUTPUT
RECAP: THE RENDERING ENGINE FLOW
1. PROCESS HTML MARKUP AND BUILD THE DOM TREE
2. PROCESS CSS MARKUP AND BUILD THE CSSOM TREE
3. COMBINE THE DOM AND CSSOM INTO A RENDER TREE
4. RUN LAYOUT ON THE RENDER TREE TO COMPUTE GEOMETRY OF EACH NODE
5. PAINT THE INDIVIDUAL NODES TO THE SCREEN
5) PAINT THE INDIVIDUAL NODES TO THE SCREEN
5) PAINT THE INDIVIDUAL NODES TO THE SCREEN
The process has visual information about every element of
the render tree.
it will create layers, from bottom to top.
absolute positioned elements and children has their own
layers.
incremental process, builds up over 12 phases, first
background, then borders etc.
it produces bitmaps, upload them in the gpu as a texture,
composites them into a final image to render to the screen.
FINAL OUTPUT
FINAL OUTPUT

Html css workshop, lesson 0, how browsers work

  • 1.
    INTRODUCTION TO FRONTEND WEB DEVELOPMENT
  • 2.
    INDEX How browsers work Level1: HTML Level 2: CSS Level 3: Layouts Level 4: Advanced HTML Level 5: CSS Ninja Level 6: JavaScript Beginner
  • 3.
    OBJECTIVE A complete page,using Bootstrap, no JavaScript
  • 4.
    INTRODUCTION TO FRONTEND WEB DEVELOPMENT 0) HOW BROWSERS WORK
  • 5.
  • 6.
  • 7.
    BROWSER COMPONENTS 1. Theuser interface 2. The browser engine 3. The rendering engine 4. Networking 5. UI backend 6. JavaScript interpreter. 7. Data storage.
  • 8.
    BROWSER COMPONENTS 3. Therendering engine 1. The user interface 2. The browser engine 4. Networking 5. UI backend 6. JavaScript interpreter. 7. Data storage.
  • 9.
  • 10.
    PAGE.HTML <!DOCTYPE html> <html> <head> <link href="style.css"rel="stylesheet"> <title>Title</title> </head> <body> <p>Hello <span>world!</span></p> <div> <img src="photo.jpg"> </div> </body> </html>
  • 11.
    STYLE.CSS body { font-size: 16px; } p{ font-weight: bold; } p span { display: none; } img { float: right; }
  • 12.
    1) PROCESS HTMLMARKUP AND BUILD THE DOM TREE
  • 13.
    1) PROCESS HTMLMARKUP AND BUILD THE DOM TREE 1. The browser sends a request to the server and reads the raw bytes of the HTML file. 20 20 20 20 26 6c 74 3b 21 44 4f 43 54 59 50 45 20 68 74 6d 6c 3e 20 20 20 20 20 20 26 6c 74 3b 68 74 6d 6c 3e 20 20 20 20 20 20 26 6c 74 3b 68 65 61 64 3e 20 20 20 20 68 72 65 66 3d 5c 22 73 74 79 6c 65 2e 63 73 73 5c 22 20 72 65 6c 3d 5c 22 73 74 79 6c 65 73 68 65 65 74 5c 22 3e 20 20 20 20 20 20 3c
  • 14.
    1) PROCESS HTMLMARKUP AND BUILD THE DOM TREE 2. it translates them to individual characters based on specified encoding of the file (e.g. UTF-8). 1. The browser sends a request to the server and reads the raw bytes of the HTML file. <html><head>...</head><body><p>Hello <span>world!</span></p ></body>...
  • 15.
    1) PROCESS HTMLMARKUP AND BUILD THE DOM TREE 3. it converts strings of characters into distinct tokens specified by the W3C HTML5 standard - e.g. <html>, <body>. 1. The browser sends a request to the server and reads the raw bytes of the HTML file. 2. it translates them to individual characters based on specified encoding of the file (e.g. UTF-8).
  • 16.
    1) PROCESS HTMLMARKUP AND BUILD THE DOM TREE 4. it converts the tokens into objects which define their properties and rules. 1. The browser sends a request to the server and reads the raw bytes of the HTML file. 2. it translates them to individual characters based on specified encoding of the file (e.g. UTF-8). 3. it converts strings of characters into distinct tokens specified by the W3C HTML5 standard - e.g. <html>, <body>.
  • 17.
    1) PROCESS HTMLMARKUP AND BUILD THE DOM TREE 5. it links the created objects in a tree data structure that also captures the parent-child relationships defined in the original markup. The DOM tree is created. 1. The browser sends a request to the server and reads the raw bytes of the HTML file. 2. it translates them to individual characters based on specified encoding of the file (e.g. UTF-8). 3. it converts strings of characters into distinct tokens specified by the W3C HTML5 standard - e.g. <html>, <body>. 4. it converts the tokens into objects which define their properties and rules.
  • 18.
    THE DOCUMENT OBJECTMODEL TREE It is the object presentation of the HTML document and the interface of HTML elements to the outside world, e.g. JavaScript.
  • 19.
    1) PROCESS HTMLMARKUP AND BUILD THE DOM TREE The browser builds up the DOM incrementally. The root of the tree is the Document object. HTML is quite forgiving by nature, almost one to one relation to the markup. CSS, images and scripts are downloaded as soon as possible by the HTML parser. JavaScript execution blocks on CSSOM, scripts should go at the end of the page and CSS at the top or inline. JavaScript blocks DOM construction unless explicitly declared as async.
  • 20.
  • 21.
    2)PROCESS CSS MARKUPAND BUILD THE CSSOM TREE
  • 22.
    2)PROCESS CSS MARKUPAND BUILD THE CSSOM TREE
  • 23.
  • 24.
    2)PROCESS CSS MARKUPAND BUILD THE CSSOM TREE The CSSOM cannot be built incrementally like the DOM. DOM and CSSOM are independent data structures. By default, CSS is treated as a render blocking resource. All CSS resources, regardless of blocking or non-blocking behavior, are downloaded and combined. Complexity around matching rules. More nesting in the CSS affects performance, we need to optimize selectors.
  • 25.
  • 26.
    3)COMBINE THE DOMAND CSSOM INTO A RENDER TREE
  • 27.
    3)COMBINE THE DOMAND CSSOM INTO A RENDER TREE DOM tree CSSOM tree
  • 28.
    3)COMBINE THE DOMAND CSSOM INTO A RENDER TREE
  • 29.
    3)COMBINE THE DOMAND CSSOM INTO A RENDER TREE It is the visual rapresentation of the document. It enables the browser to paint elements in the screen in the right order. Each element in the tree is called renderer or render- object or frame. A renderer knows how to layout and paint itself and it's children. A renderer represents a rectangular area and contains geometric informations such as width, height, position. Every DOM element has a reference to the node in the render tree. Elements with display:none; or head tags are in the DOM but not in the render tree. Not one to one with the DOM.
  • 30.
  • 31.
    4) RUN LAYOUTON THE RENDER TREE TO COMPUTE GEOMETRY OF EACH NODE
  • 32.
    4) RUN LAYOUTON THE RENDER TREE TO COMPUTE GEOMETRY OF EACH NODE The browser begins at the root of the render tree and traverses it to compute the geometry of each object on the page. This stage is also known as reflow. When the changes affect the document contents or structure, or an element position, a reflow (or relayout) happens. When changing element styles which don't affect the element's position on a page (such as background-color, border-color, visibility), a repaint happens. Batch changes, intelligent reflow. Reflow only dirty trees in the tree. Accessing certain properties, e.g. with JS will immediately reflow.
  • 33.
    4) RUN LAYOUTON THE RENDER TREE TO COMPUTE GEOMETRY OF EACH NODE <html> <head> <title>Layout example</title> </head> <body> <div style="width: 50%"> <div style="width: 50%">Hello!</div> </div> </body> </html>
  • 34.
    4) RUN LAYOUTON THE RENDER TREE TO COMPUTE GEOMETRY OF EACH NODE
  • 35.
  • 36.
  • 37.
    RECAP: THE RENDERINGENGINE FLOW 1. PROCESS HTML MARKUP AND BUILD THE DOM TREE 2. PROCESS CSS MARKUP AND BUILD THE CSSOM TREE 3. COMBINE THE DOM AND CSSOM INTO A RENDER TREE 4. RUN LAYOUT ON THE RENDER TREE TO COMPUTE GEOMETRY OF EACH NODE 5. PAINT THE INDIVIDUAL NODES TO THE SCREEN
  • 38.
    5) PAINT THEINDIVIDUAL NODES TO THE SCREEN
  • 39.
    5) PAINT THEINDIVIDUAL NODES TO THE SCREEN The process has visual information about every element of the render tree. it will create layers, from bottom to top. absolute positioned elements and children has their own layers. incremental process, builds up over 12 phases, first background, then borders etc. it produces bitmaps, upload them in the gpu as a texture, composites them into a final image to render to the screen.
  • 40.
  • 41.