5. One Billion loop Performance for language
time.c
time.py
time.js
time.php
Can you guess who the fastest?
time.c 0.28s time.js 0.19s time.php 10s time.python 5.46599197388s
6. Where's web program different than common program?
We need more and more things to do.
7. Fat client,thin client;
B/S or ERP;
Web site;
Web game;
More and more.
Back-end or Front-end
development and optimization.
Historical issues.
11. 1,You type an URL into address bar in your preferred browser.
2,The browser parses the URL to find the protocol, host, port, and path.
3,It forms a HTTP request (that was most likely the protocol)
4,To reach the host, it first needs to translate the human readable host into an IP number,
and it does this by doing a DNS lookup on the host
5,Then a socket needs to be opened from the user’s computer to that IP number, on the port specified (most often port 80)
6,When a connection is open, the HTTP request is sent to the host
7,The host forwards the request to the server software (most often Apache) configured to listen on the specified port
8,The server inspects the request (most often only the path), and launches the server plugin needed to
handle the request (corresponding to the server language you use, PHP, Java, .NET, Python?)
9,The plugin gets access to the full request, and starts to prepare a HTTP response.
10,To construct the response a database is (most likely) accessed. A database search is made, based on parameters in the
path (or data) of the request
11,Data from the database, together with other information the plugin decides to add, is combined into a long string of text
(probably HTML).
12,The plugin combines that data with some meta data (in the form of HTTP headers), and sends the HTTP response back
to the browser.
13,The browser receives the response, and parses the HTML (which with 95% probability is broken) in the response
14,A DOM tree is built out of the broken HTML
15,New requests are made to the server for each new resource that is found in the HTML source (typically images, style
sheets, and JavaScript files). Go back to step 3 and repeat for each resource.
16,Stylesheets are parsed, and the rendering information in each gets attached to the matching node in the DOM tree
17,Javascript is parsed and executed, and DOM nodes are moved and style information is updated accordingly
18,The browser renders the page on the screen according to the DOM tree and the style information for each node
19,You see the page on the screen
20,You get annoyed the whole process was too slow.
https://github.com/chaosmical/HTTP-headers-status-CN/raw/master/http-headers-status-CN.jpg
18. HTTP and browsers limit
Get fast than post
URLs over 2,000 characters will not work in the most popular web browser.
HTTP1.1 persistent connection
HTTP 1.1 HTTP 1.0 complicated the same domain
IE 6,7 2 4
IE 8 6 6
Firefox 2 2 8
Firefox 3 6 6
Safari 3, 4 4 4
Chrome 1,2 6 ?
Chrome 3 4 4
Opera 9.63,10.00alpha 4 4
One client 300 Cookie , One domain 20 Cookie
IE: css 31 stylesheet
19. Handle slowly users
var someapp = new app();
someapp.init();
var someapp = new app();
$.extend(someapp,{
Speed:null,
checkSpeed:function(){
var self = this,timeout = 10000;
self.Speed =
setTimeout(function(){
$.trigger(“slowly”,[self]);
},timeout);
},
closeCheckSpeed:function(){
clearTimeout(this.Speed);
22. Css Rendering
1,Use efficient CSS selectors
2,Avoid CSS expressions
3,Put CSS in the document head
4,Specify a character set
5,Avoid reflow and repaint by specifying image
dimension
6,CSS3 Selectors
Speed vs Practicality
23. Javascript Execute
Order
Loading and Execution
Data Access and Cache(closures,scope)
DOM Scripting
Repaints and Reflows
Event Delegation
Algorithms and Flow Control
String and Regular Expressions(trim)
http://blog.stevenlevithan.com/archives/faster-trim-javascript
Responsive Interfaces
Ajax(MXHR,Data Format)
24. Test and code refactoring
refactoring based on Test
Write Testable code
Ui test and Unit test
25. Some code skills
Avoid Double Evaluation
Use Object/Array Literals
Don't repeat work
Lazy/Conditional Advance Loading(code or assets)
Bitwise Operators
Native Methods
29. Seo
Define keywords
In order of popularity
Removed Repeat keywords
Top three is title
Description meta tag
Keywords meta tag
h1-h6
Keywords appear tactics
Content for keywords(uri is title,tags cloud)
30. More choose for user
Slowly user
Special user
Disability user
Different terminal user