Top Banner
Introduction to Browser Internals Sivasubramaniam Arunachalam Sep 14, 2013 @sivaa_in http://barcampbangalore.org/bcb/bcb14/introduction-to-browser-internals
98

Introduction to Browser Internals

Jan 13, 2015

Download

Technology

Session given in Barcamp Bangalore Monsoon 2013.
barcampbangalore.org/bcb/bcb14/introduction-to-browser-internals
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 2: Introduction to Browser Internals

It’s me!

Page 3: Introduction to Browser Internals
Page 4: Introduction to Browser Internals

It’s about you!

#barcampblr

#browser

Page 5: Introduction to Browser Internals

Just Before We Get

Started

Page 6: Introduction to Browser Internals

How many of you use

Internet Explorer

as your

Primary Browser?

Page 7: Introduction to Browser Internals

http://www.w3schools.com/browsers/browsers_stats.asp

Page 8: Introduction to Browser Internals

http://www.w3schools.com/browsers/browsers_stats.asp

Where do you fit?

Page 9: Introduction to Browser Internals

The rise (Chrome) and fall (IE)

Page 10: Introduction to Browser Internals

http://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Usage_share_of_web_browsers_%28Source_StatCounter%29.svg/600px-Usage_share_of_web_browsers_%28Source_StatCounter%29.svg.png

Page 11: Introduction to Browser Internals

The Past

Page 12: Introduction to Browser Internals

Now

Page 13: Introduction to Browser Internals
Page 14: Introduction to Browser Internals

Chrome

Page 15: Introduction to Browser Internals

Chrome

What’s wrong?

Page 16: Introduction to Browser Internals

Chrome

It’s Chrome. Not Google Chrome

Page 17: Introduction to Browser Internals

Content

Page 18: Introduction to Browser Internals

Dream to build an Operating System? Build a Browser First

Page 19: Introduction to Browser Internals

Computer Users Spent more time on?

Page 20: Introduction to Browser Internals

1 Billion Mobile Devices Alone (Android + iOS)

Page 21: Introduction to Browser Internals

Hello Web Developers! Know your platform

Page 22: Introduction to Browser Internals

Black Box

White Box Open

Page 23: Introduction to Browser Internals

Parts of a Web Page

Page 24: Introduction to Browser Internals

Just Contents. Nothing Else

• Text

• Links

• Images

Page 25: Introduction to Browser Internals

Video

Page 26: Introduction to Browser Internals

Classical Web

Web Server Web Browser HTML + CSS

Page 27: Introduction to Browser Internals

Web Browser Engine

<h1> BarCamp </h1> h1 { color:rgb(255,0,0); }

BarCamp

Page 28: Introduction to Browser Internals

What Layout Engine will do?

• Parsing

• DOM Construction

• Resource Dispatching & Loading

• Event Handling

• Painting

• JS Bindings

Page 29: Introduction to Browser Internals
Page 30: Introduction to Browser Internals
Page 31: Introduction to Browser Internals
Page 32: Introduction to Browser Internals
Page 33: Introduction to Browser Internals
Page 34: Introduction to Browser Internals

The Internals

• All are Objects

• Document Object Model

<html> Root Document • <head>

• <title>

• <body>

• <h1>

Page 35: Introduction to Browser Internals

Access & Manipulation

• Web 1.0 (~ 0% Dynamic)

• Web 2.0

Objects are Waiting

• DOM

Need a Language

• Java Script

Page 36: Introduction to Browser Internals
Page 37: Introduction to Browser Internals

The Big Picture

Page 38: Introduction to Browser Internals
Page 39: Introduction to Browser Internals

OO DOM

• Members / Properties

• Methods / Behaviors

• Other Objects (recursive)

• DOT Notation

Examples:

• document.title

• Window.print()

Page 40: Introduction to Browser Internals

Internal Objects of DOM

• window

• document

• navigator

• screen

• history

• location

Page 41: Introduction to Browser Internals

DOM - Hierarchy

Node

Element

HTML Element

HTML Input Element

HTML Table Element

Page 42: Introduction to Browser Internals

DOM - Versions

Legacy Intermediate

Standard (W3C) DOM 1

DOM 2 (getElementById)

DOM 3 (Xpath)

DOM 4

Page 43: Introduction to Browser Internals

DOM Objects Lets Explore it in Chrome

Page 44: Introduction to Browser Internals

Lets do a magic!

Page 45: Introduction to Browser Internals
Page 46: Introduction to Browser Internals

How many changes?

Page 47: Introduction to Browser Internals
Page 48: Introduction to Browser Internals

// Create and add Reset Box

var reset_box = document.createElement(‘input’)

reset_box.type = 'reset'

document.forms[0].appendChild(reset_box)

// Change the button Label

document.getElementById("gbqfsa").innerHTML = "SAP Search"

// Change the Font Size of footer

document.getElementById("flls").style.fontSize = '2em'

// Change the branding image

document.images[1].src = "http://upload.wikimedia.org/wikipedia/en/e/e4/Logo_SAP.gif"

Page 49: Introduction to Browser Internals

Lets browse www.google.com

(other than Google Chrome)

Page 50: Introduction to Browser Internals
Page 51: Introduction to Browser Internals
Page 52: Introduction to Browser Internals

How is it possible?

Page 53: Introduction to Browser Internals
Page 54: Introduction to Browser Internals

No No! Rajinikanth is not working for Chrome.

Page 55: Introduction to Browser Internals

No Magic at All Its all about awesome engineering

(Lets revisit the basics)

Page 56: Introduction to Browser Internals

A Brand New Request

Parse the URL

Domain

Protocol DNS Resolve

TCP Connection

HTTP Request

Page 57: Introduction to Browser Internals

The Response

Page 58: Introduction to Browser Internals

HTTP/1.1 200 OK Content-Type: application/xhtml+xml

XML Mode

Page 59: Introduction to Browser Internals
Page 60: Introduction to Browser Internals

HTTP/1.1 200 OK Content-Type: application/xhtml+xml

Content-Type: text/html

Page 61: Introduction to Browser Internals

HTTP/1.1 200 OK Content-Type: application/xhtml+xml

Content-Type: text/html

<html>

Page 62: Introduction to Browser Internals

HTTP/1.1 200 OK Content-Type: application/xhtml+xml

Content-Type: text/html

<html>

Quirks Mode

Page 64: Introduction to Browser Internals

HTTP/1.1 200 OK Content-Type: application/xhtml+xml

Content-Type: text/html

<!doctype html>

<html>

Standard Mode

Page 65: Introduction to Browser Internals

Sample HTML

Page 66: Introduction to Browser Internals

DOM Tree

Page 67: Introduction to Browser Internals

•Image •CSS

• JavaScript

Sub Resources

Page 68: Introduction to Browser Internals

• Non-Blocking • Image Decoder

• Paint

Image

Page 69: Introduction to Browser Internals

• Non-Blocking

• Bucket Identification

• Style Matching

• Element to CSS Selector

• Not like JS

CSS

Page 70: Introduction to Browser Internals

• ~ Blocking

• <script>

• document.write()

JavaScript – Classical Browsers

Page 71: Introduction to Browser Internals

• Non Blocking

• No DOM Tree

• Parsing the HTML

JavaScript – Modern Browsers

Page 73: Introduction to Browser Internals

JavaScript & DOM

= Programming Language + DB

Page 74: Introduction to Browser Internals
Page 75: Introduction to Browser Internals
Page 76: Introduction to Browser Internals

• View Port

• Block

• Scroll

• Block

• Text

Frame Construction

Page 77: Introduction to Browser Internals
Page 78: Introduction to Browser Internals

• Positions

• Dimensions

• Related Attributes

• Margin

• Padding

Layout Construction

Page 79: Introduction to Browser Internals

http://www.youtube.com/watch?v=dndeRnzkJDU

Page 80: Introduction to Browser Internals
Page 81: Introduction to Browser Internals
Page 82: Introduction to Browser Internals

• Mostly done by CPU

• Now, delegates to GPU

Painting

Page 83: Introduction to Browser Internals

A Scrollable Page with Fixed

Background Image

Page 84: Introduction to Browser Internals

Lets Talk about the RajiniKanth Factor

Chrome’s Network Stack

Page 85: Introduction to Browser Internals

Average Web Page Size?

# of Sub Resources?

Page 86: Introduction to Browser Internals

DNS Resolve

Page 87: Introduction to Browser Internals

DNS Pre Resolve

Page 88: Introduction to Browser Internals

How about Wikipedia?

Page 89: Introduction to Browser Internals

TCP Connect

Page 90: Introduction to Browser Internals

TCP Pre Connect

Page 92: Introduction to Browser Internals

Pooling & Reuse, Caching

Page 93: Introduction to Browser Internals

Chrome Internals chrome://dns chrome://omnibox/ chrome://net-internals/ chrome://predictors chrome://histograms/DNS.PrefetchResolution chrome://cache

Page 94: Introduction to Browser Internals

Where to Start?

http://www.macdevcenter.com/lpt/a/4570

WebKit? Chrome? (5GB)

Page 95: Introduction to Browser Internals

libwww

Page 96: Introduction to Browser Internals

BYOB (Build Your Own Browser)

http://www.macdevcenter.com/lpt/a/4570

Page 97: Introduction to Browser Internals

Thank You! [email protected]

bit.ly/sivasubramaniam bit.ly/sivaa_in

Page 98: Introduction to Browser Internals

References http://www.clker.com/cliparts/6/7/0/f/o/X/birthday-cake-four-candles-md.png http://leashsstuff.blogspot.in/2011/06/browser-cartoon.html https://blog.mozilla.org/webdev/2012/05/04/how-browser-engines-work/