8. Web Browsers
• Google Chrome
• Mozilla Firefox
• Safari
• Opera
• Internet Explorer
8
9. Mobile Browsers
• Safari
• Android Browser
• BlackBerry Browser
• Opera Mobile
9
10. Browsers engines
• Trident is developed by Microsoft (Windows)
• Tasman was developed by Microsoft (Macintosh)
• Gecko is developed by the Mozilla Foundation
• KHTML is developed by the KDE project
• WebKit is a fork of KHTML by Apple Inc.
10
13. IE:Mac - The Innovation
• Support for annotative glosses to • An option to change the browser color,
Japanese kanji and Chinese characters to match the colors of the iMac G3. The
first builds had a choice of 9 colors, but
• Scrapbook feature lets the user archive later builds had 15.
any page in its current state.
• Print Preview functionality allowing for
• Auction Manager feature automatically adjustment of the font-size from within
the preview pane.
tracks eBay auctions.
• Robust PNG support (version 5.0) • Page Holder sidebar functionality
allowing users to hold a page in the
sidebar
13
16. • The user interface - this includes the • Networking - used for network calls, like
address bar, back/forward button, HTTP requests. It has platform
bookmarking menu etc. Every part of independent interface and underneath
the browser display except the main implementations for each platform.
window where you see the requested
page. • UI backend - used for drawing basic
widgets like combo boxes and windows.
• The browser engine - the interface for
querying and manipulating the rendering
engine.
• JavaScript interpreter. Used to parse and
execute the JavaScript code.
• The rendering engine - responsible for • Data storage. This is a persistence layer.
displaying the requested content. For The browser needs to save all sorts of
example if the requested content is data on the hard disk, for examples,
HTML, it is responsible for parsing the cookies, HTML5 web database.
HTML and CSS and displaying the
parsed content on the screen.
16
17. Parsing HTML
• Document Object Model is the object
<html>
<body>
<p>
presentation of the HTML document Hello World
</p>
and the interface of HTML elements to <div> <img src="example.png" alt="" /></div>
</body>
the outside world </html>
17
19. JavaScript parsing
• The model of the web is synchronous. Authors expect scripts to be
parsed and executed immediately when the parser reaches a <script>
tag. The parsing of the document halts until the script was executed. If
the script is external then the resource must be first fetched from the
network - this is also done synchronously, the parsing halts until the
resource is fetched. This was the model for many years and is also
specified in HTML 4 and 5 specifications.
• http://www.whatbrowser.org/en/more/
19
20. Browsers error tolerance
• You never get an "Invalid Syntax" error on an page served as text/
html. Browsers fix an invalid content and go on.
20
26. • HTML 4.01 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//
EN" "http://www.w3.org/TR/html4/strict.dtd">
• XHTML 1.0 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
• HTML 5 <!DOCTYPE html>
26
32. A basic HTML5 document
<!DOCTYPE html>
<html>
<head>
<title>Sample page</title>
</head>
<body>
<h1>Sample page</h1>
<p>This is a <a href="demo.html">simple</a> sample.</p>
<!-- this is a comment -->
</body>
</html>
32
33. DOM tree
DOCTYPE: html
html
head
#text: ␣␣
title
#text: Sample page
#text: ␣
#text: ␣
body
#text: ␣␣
h1
#text: Sample page
#text: ␣␣
p
#text: This is a
a href="demo.html"
#text: simple
#text: sample.
#text: ␣␣
#comment: this is a comment
#text: ␣
33
48. JavaScript
• JavaScript is an implementation of the ECMAScript language standard
and is typically used to enable programmatic access to computational
objects within a host environment. It can be characterized as a
prototype-based object-oriented scripting language that is dynamic,
weakly typed and has first-class functions. It is also considered a
functional programming language like Scheme and OCaml because it
has closures and supports higher-order functions.
48
49. Doug Crockford
• "JavaScript doesn't suck.You're just doing it wrong."
49
58. // Variable declaration
var firstName = "Apple";
// Function declaration
function saying () {
return "Hello Apple!";
}
typeof firstName // string
typeof saying // function
58
59. // Object declaration
var apple = {
firstName : "Apple"
};
// Array declaration
var fruits = ["Apple", "Orange"];
typeof apple // object
typeof fruits // object
59
60. // Object declaration
var apple = {
firstName : "Apple"
};
// Array declaration
var fruits = ["Apple", "Orange"];
apple instanceof Array // false
fruits instanceof Array // true
60
61. // Various "false" values
var nullVal = null;
var undefinedVal = undefined;
var zeroVal = 0;
var falseVal = false;
var emptyString = "";
// All would equal false in an if-
clause
if (emptyString) {
// Would never go in here
}
61
64. // Prevent type coercion
var sum = parseInt("5", 10) + 6 + 7; // 18
64
65. // Using the arguments collection
function fruits () {
var allFruits = [];
for (var i=0, il=arguments.length; i<il; i++) {
allFruits.push(arguments[i]); return allFruits.join(" & ");
}
}
// Apple and Orange
fruits("Apple", "Orange");
// Apple
friends("Apple");
65
67. // Object declaration, literal style
var fruit = {
name : "Apple",
color : "green"
};
67
68. // Iterating over properties
for (var item in fruit) {
console.log(item + ": " + fruit[item]);
}
68
69. // Object declaration
var fruit = {
name : "Apple"
};
// Safe check for property
if ("name" in fruit) {
console.log(fruit.name);
}
69
70. // Object declaration
function Apple {
this.color = "Green";
};
// Method set via prototype
Apple.prototype.green = function
() {
return true;
};
70
71. // Scope - global or local
// Global
var quote = "Stay Hungry. Stay Foolish."
function () {
// Local
var green = "Apple";
// Global
wojtek = "Fiery Red";
}
71
74. Firebug
• Inspect and edit HTML • Execute JavaScript on the fly
• Edit CSS • Logging for JavaScript
• Visualize CSS metrics
• Monitor network activity
• Debug and profile JavaScript
• Show errors
• Explore the DOM
74
76. YSlow
• Make fewer HTTP requests • Put JavaScript at bottom
• Use a Content Delivery Network • Avoid CSS expressions
(CDN)
• Make JavaScript and CSS external
• Avoid empty src or href
• Reduce DNS lookups
• Add Expires headers
• Minify JavaScript and CSS
• Compress components with gzip
• Avoid URL redirects
• Put CSS at top
• Remove duplicate JavaScript and CSS
76
77. YSlow
• Configure entity tags (ETags) • Avoid AlphaImageLoader filter
• Make AJAX cacheable • Do not scale images in HTML
• Use GET for AJAX requests • Make favicon small and cacheable
• Reduce the number of DOM elements
• Avoid HTTP 404 (Not Found) error
• Reduce cookie size
• Use cookie-free domains
77
79. Page Speed
• Optimizing caching — keeping your application's data and logic off the
network altogether
• Minimizing round-trip times — reducing the number of serial request-
response cycles
• Minimizing request overhead — reducing upload size
• Minimizing payload size — reducing the size of responses, downloads,
and cached pages
• Optimizing browser rendering — improving the browser's layout of a
page
79
81. Web Developer
• The Web Developer extension adds various web developer tools to a
browser. The extension is available for Firefox and Chrome, and will
run on any platform that these browsers support including Windows,
Mac OS X and Linux.
81
84. Performance
• Psychology - effect of waiting - make people happy
• Optimization
84
85. Minimize HTTP Requests
• 80% of the end-user response time is spent on the front-end. Most of
this time is tied up in downloading all the components in the page:
images, stylesheets, scripts, Flash, etc. Reducing the number of
components in turn reduces the number of HTTP requests required
to render the page. This is the key to faster pages.
85
86. Use a Content Delivery Network
• Deploying your content across multiple, geographically dispersed
servers will make your pages load faster from the user's perspective.
86
87. Add an Expires or a Cache-
Control Header
• For static components: implement "Never expire" policy by setting far
future Expires header
• For dynamic components: use an appropriate Cache-Control header
to help the browser with conditional requests
87
88. Gzip Components
• The time it takes to transfer an HTTP request and response across
the network can be significantly reduced by decisions made by front-
end engineers.
88
89. Put StyleSheets at the Top
• Putting stylesheets in the HEAD allows the page to render
progressively.
89
90. Put JavaScript at the Bottom
• The problem caused by scripts is that they block parallel downloads.
The HTTP/1.1 specification suggests that browsers download no
more than two components in parallel per hostname.
90
91. Avoid CSS Expressions
• CSS expressions are a powerful (and dangerous) way to set CSS
properties dynamically.
91
92. Make JavaScript and CSS External
• Using external files in the real world generally produces faster pages
because the JavaScript and CSS files are cached by the browser.
JavaScript and CSS that are inlined in HTML documents get
downloaded every time the HTML document is requested.
92
93. Reduce DNS Lookups
• DNS has a cost. It typically takes 20-120 milliseconds for DNS to
lookup the IP address for a given hostname.
93
94. Avoid Redirects
• It hurts performance to include the same JavaScript file twice in one
page.
94
95. Configure ETags
• An ETag is a string that uniquely identifies a specific version of a
component.
HTTP/1.1 200 OK
Last-Modified: Tue, 12 Dec 2006 03:03:59 GMT
ETag: "10c24bc-4ab-457e1c1f"
Content-Length: 12195
95
96. Make AJAX Cacheable
• When users request a page, it can take anywhere from 200 to 500ms
for the backend server to stitch together the HTML page. During this
time, the browser is idle as it waits for the data to arrive. In PHP you
have the function flush(). It allows you to send your partially ready
HTML response to the browser so that the browser can start fetching
components while your backend is busy with the rest of the HTML
page.
96
97. Use GET for AJAX Requests
• POST is implemented in the browsers as a two-step process: sending
the headers first, then sending data. So it's best to use GET, which only
takes one TCP packet to send (unless you have a lot of cookies). The
maximum URL length in IE is 2K.
97