SlideShare a Scribd company logo
1 of 49
Download to read offline
Tuning Web Performance
    in Frontend Perspective

  Lin-Chieh Shangkuan (上官林傑)
         ericsk@gmail.com
AGENDA

 The Impacts of Web Performance
 Development Tools
 Website Optimization Concepts
 References
The Impact of Performance

 Longer response time from web server.
 Too many requests (css/javascript files, images, flashes, ...)
 Complicated DOM structure
 Inefficient JavaScript codes
 ....
The Impact of Performance

 Longer response time from web server.
 Too many requests (css/javascript files, images,
 flashes, ...)
 Complicated DOM structure
 Inefficient JavaScript codes


                                80~90% time spent
                                on the frontend
Page-loading Samples
Development Tools

 Firefox
 http://getfirefox.com/
 Firebug
 http://getfirebug.com/
 Page Speed (Firebug plugin)
 http://code.google.com/speed/page-speed/
 Y!Slow
 http://developer.yahoo.com/yslow/
Development Tools (cont)

 Chrome (Chromium/WebKit) Developer Tools
 http://www.chromium.org/devtools
 Install AMAP Latest Web Browsers
 e.g. IE8/9 (preview), Firefox 3.6/nightly, Safari 4/WebKit,
 Chrome/Chromium, Opera 10/10.5
Firebug Console

 Debugging your JavaScript code.
    Use console object in your JavaScript code.
    Interactive in the console tab.
Requests Analysis

 Analyzing the requests.
Listen to Suggestions

 Follow the suggestions from PageSpeed (or Y!Slow)
Chromium Devtools
HTTP Overviews

Request:
  GET /foo/bar.js HTTP/1.1
  Host: example.com
  User-Agent: Mozilla/5.0

Response:
  HTTP/1.1 200 OK
  Content-Type: application/x-javascript
  Last-Modified: Mon, 15 Mar 2010 10:00:00 GMT
  Content-Length: 1234

  (function(){ .....
HTTP Reuqest Example
$ telnet ajax.googleapis.com 80
Trying 74.125.153.95...
Connected to googleapis-ajax.l.google.com.
Escape character is '^]'.
GET /ajax/libs/jquery/1.4.2/jquery.min.js HTTP/1.1
Host: ajax.googleapis.com
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; zh-TW; rv:1.9.2)
Gecko/20100115 Firefox/3.6 GTB7.0
Accept-Encoding: gzip,deflate

HTTP/1.1 200 OK
Content-Type: text/javascript; charset=UTF-8
Last-Modified: Mon, 15 Feb 2010 23:30:12 GMT
Date: Mon, 15 Mar 2010 08:39:18 GMT
Expires: Tue, 15 Mar 2011 08:39:18 GMT
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
Server: sffe
Content-Encoding: gzip
Cache-Control: public, max-age=31536000
Age: 2497
Content-Length: 24678
X-XSS-Protection: 0

;iw?F???+??m?@ə???v?I։/M???6???????$e???...
Ways to Speed up the Website

 Optimize the backend processing
    e.g., PHP engine, database, ....
 Scaling Transfers
    Co-location, CDN, ...
 Reducing the browser's requests
    CSS sprites, expire headers, http compression...
 Optimizing the contents
    Defer loading, rearrangement, ...
 Efficient JavaScript development
    Improving the programming techs, ...
Scaling Transfers

 Use CDN
    e.g., Akamai, Amazon S3, ...
    Pixnet experience: http://www.slideshare.net/gslin/using-cdn-
    to-improve-performance
 Reduce DNS Lookups
    Keep-Alive
    fewer domains
 Avoid Redirects
 Use Comet
Scaling Transfers

 Sharding Dominant Domains
  browser     HTTP/1.1   HTTP/1.0
  IE6, 7      2          4

  IE8         6          6

  FF2         2          8

  FF3         6          6

  Saf         4          4

  Chrome      6          6

  Op          4          4


        Connections per server
Reducing Requests
HTTP Compression

 Modern browsers support HTTP compression -- to reduce
 the size of response content
   Gzip the static (html, css, js, ...) files
   Don't compress everything (e.g., jpg, png, pdf, ... they are
   already compressed)
 Check if the Accept-Encoding header has gzip or deflate value.
   Respond Content-Encoding: gzip header.
HTTP Compression

   In Apache httpd server, use mod_gzip (httpd 1.3) or
   mod_deflate (httpd 2.x).

[mod_deflate]
AddOutputFilterByType DEFLATE text/html text/css
application/x-javascript

   Problems:
      Proxy may cache uncompressed content
          Add Vary: Accept-Encoding header
      IE6 bug: Q312496, Q313712
Make Fewer Requests

 CSS Sprites: Combine N icons into 1 bigger image.
    Reduce N requests info 1 request.
    Be careful of the arrangement of the icons
    sample: http://www.google.com.tw/images/nav_logo8.png
    tool: http://tw.spritegen.website-performance.org/
    http://csssprites.com/
 Combine CSS/JavaScript files
    Using Google Closure Compiler
    Apache: http://code.google.com/p/modconcat/
    Lighttpd: http://code.google.com/p/lighttpd-mod-concat/
    YUI Comobo Handler: http://yuiblog.
    com/blog/2008/07/16/combohandler/
Make Fewer Requests

 Reduce Cookie size (or split domains)
 Inline images: using base64 encoding
    <img src="data:image/png;base64, xxxxx">
    IE7/6 doesn't support this feature
    Useful in mobile browser
    Not only images: <frame src="data:text/html,%3Chtml%3E%
    3Cbody%20style%3D%22background..."></frame>
Using Expires Headers

 Use Expires header to tell the browser how long to keep
 the resource.
    Browser won't fetch the resource again until the expire time
    Apache mod_expires module can help setting expire time
        <FilesMatch ".(css|js|jpg|png)$">
            ExpiresDefault "access plus 1 year"
        </FilesMatch>
    e.g., Expires: Fri, 25 Mar 2011 08:00:00 GMT
 Cache-Control header
    In stead of using a specified date, Cache-Control header
    shows HOW LONG the client should keep it
    e.g., Cache-Control: max-age=31536000 # cache 1 year
Using Last-Modified Headers

    Use Last-Modified header to tell the browser the last modified
    time of the resource.

[request]                             [request]
GET /foo/bar.css HTTP/1.1             GET /foo/bar.css HTTP/1.1
....                                  ...
                                      If-Modified-Since: Thu, 25 Mar 2010
[response]                            10:00:00 GMT
HTTP/1.1 200 OK                       ...
Content-Type: text/css
Last-Modified: Thu, 25 Mar 2010 10:   [response]
00:00 GMT+8                           HTTP/1.1 304 Not Modified
....                                  ...
                                      (empty response body)
Configuring ETag

 ETag (Entity Tag) header tells browser which to cache
    How ETag works: read Wikipedia
 Problem: Not-the-same tag across different servers
    Apache: inode-size-timestamp
    IIS: timestamp:changenumber

 Solution:
    Set ETag manually
    Remove it.
        (in Apache) FileETag none
Invalidates the Cached Resources

 If the static resources are cached, how to invalidate them?
    Use signature in filename ( /js/foo.AB32FDC.js )
    Add query string ( /js/foo.js?20100325110000 )
Optimizing Loadings
Minifying JavaScript
 Reduce the size of JavaScript files.
    Reduce the total response sizes.
    HTML, CSS files can be also compressed.
 Closure-compiler
    Web-based http://closure-compiler.appspot.com/
    RESTful API
    http://code.google.com/closure/compiler/docs/api-ref.html
    Standalone executable
 Ofuscation
    Reduce the length of variables names
    Be careful the obfuscation method (e.g., eval cause
    performance degradation)
    Be careful the conflicts.
Optimizing Images

 Using appropriate image format and remove redundant
 chunks in the image files.
    PNG8 (256 colors) is a good choice.
 Optimizing:
    Crushing PNGs
       pngcrush (http://pmt.sf.net/pngcrush/)
    Stripping JPEG metadata
       jpegtran (http://jpegclub.org/)
    Convert GIF to PNG
       ImageMagick
    Optimizing GIF animations
       gifsicle
       (
       (http://www.lcdf.org/gifsicle/)
    Avoid image scaling
Put Stylesheets on The Top

 Browser delays showing any visible components while it
 and user wait for the stylesheet at the bottom.
 Use <link> to include stylesheets
    @import MUST precede all other rules
    @import may cause blank white screen phenomenon (in IE)
Put JavaScripts at The Bottom

 JavaScript blocks parallel downloads
    Put at top: the other components are delayed- loaded.
 defer attributes:
    Firefox still blocks other downloads
Non-blocking Loading Scripts

 IE8 is the first browser that supports downloading scripts in
 parallel.
 Ways to load JavaScripts
    XHR Eval
    XHR Inject
    Script in iframe
    Inserting script DOM element
    document.write
Non-blocking Loading Scripts
                                                 Existing         Busy           Preserve
     Tech            Parallel      Diff Domain
                                                 Scripts        indicator         Order


    Normal           IE8, SF4          Y            Y       IE, SF4          IE, SF4


   XHR Eval              *             N            N       SF, Ch


 XHR Injection           *             N            Y       SF, Ch


Script in iframe         *             N            N       IE, FF, SF, Ch


  Script DOM             *             Y            Y       FF, SF, Ch       FF, Op


                   IE, SF4, Ch2,
 Script Defer                          Y            Y       *                *
                       FF3.1

                   IE, SF4, Ch2,
document.write                         Y            Y       *                *
                        Op
iframes

 iframes are heavy and block onload event.
 Use script DOM injection to insert ADs instead of iframes.
Efficiency Practices
Make JavaScript/CSS External

 Reusing components
 Cache the files
 Unobstrusive JavaScripts
Simplifying CSS Selectors

 CSS selector policy: Rightmost-First
 Tips:
    Avoid * selector
    Don't qualify ID/CSS selectors
    Specific rules
    Avoid descendant selectors
    Avoid Tag > Child selectors
    Rely on inheritance
Efficient JavaScript Tips

 Using className instead of modifying style attributes of a DOM
 element.
 [bad
 ]

 var foo = document.getElementById('foo');
 foo.style.color = '#f00';
 foo.style.fontWeight = 'bold';

 [good]
 .highlight {
    color: #f00;
    font-weight: bold;
 }

 foo.className = 'highlight';
Efficient JavaScript Tips (con'd)

 Appending a newly-created DOM element after modifying its
 attributes. (avoid reflows)
 [bad]
 var foo = document.createElement('div');
 document.body.appendChild(foo);
 foo.innerHTML = 'Hello, world';
 foo.className = 'hello';

 [good]
 var foo = document.createElement('div');
 foo.innerHTML = 'Hello, world';
 foo.className = 'hello';
 document.body.appendChild(foo);
Efficient JavaScript Tips

 Using document fragment to create new contents.
 [bad]
 document.body.appendChild(createDivElement());
 document.body.appendChild(createDivElement());
 ...

 [good]
 var frag = document.createDocumentFragment();
 frag.appendChild(createDivElement());
 frag.appendChild(createDivElement());
 ....
 document.body.appendChild(frag);
Efficient JavaScript Tips

 Using array join instead of directly concatenate strings.
 [bad
 ]
 ]
 var a = 'Hel';
 a += 'lo';
 a += ', wor';
 a += 'ld!';

 [good]
 var buf = ['Hel'];
 buf.push('lo');
 buf.push(', wor');
 buf.push('ld!');
 a = buf.join('');
Efficient JavaScript Tips

   Faster trim method: (use simple regular expression)
[bad]
str.replace(/^s+|s+$/g, '');

[better]
str.replace(/^s+/, '').replace(/^s+$/, '');

[much better]
str = str.replace(/^s+/, '');
for (i = str.length - 1; i >=0; i--) {
    if (/S/.test(str.charAt(i))) {
        str = str.substring(0, i + 1);
        break;
    }
}
Efficient JavaScript Tips

 Use popular JavaScript frameworks. (e.g. jQuery)
Misc.
Responsive Web Applications

 Prefetching resources
 AJAX
 Avoid long-running scripts
HTML5

 http://whatwg.org/html5
 Short tags:
    <!DOCTYPE html>
    <meta charset="UTF-8">
    <script src="xxx.js">, <style>...</style>
    <script async ...>
 Application Cache (offline data)
    https://developer.mozilla.org/En/Offline_resources_in_Firefox
    http://www.whatwg.org/specs/web-apps/current-
    work/multipage/offline.html
    http://googlecode.blogspot.com/2009/04/gmail-for-mobile-
    html5-series-using.html
 WebStorage/WebDatabase API
Mobile Web

 Mobile device has lower hardware-profile so that the web
 performance is more important!
 iPhone Safari/Android browser/Opera Mini likes HTML5 (w/
 a little CSS3)
References
Books

 High Performance Web Sites, O'Reilly
 Even Faster Web Sites
Websites

 Let's Make the Web Faster (Google)
 http://code.google.com/speed
 Exceptional Performance (Yahoo!)
 http://developer.yahoo.com/performance/
 High Performance Web Sites Blog
 http://www.stevesouders.com/blog/

More Related Content

What's hot

Front end performance optimization
Front end performance optimizationFront end performance optimization
Front end performance optimizationStevie T
 
Performance automation 101 @LDNWebPerf MickMcGuinness
Performance automation 101 @LDNWebPerf MickMcGuinnessPerformance automation 101 @LDNWebPerf MickMcGuinness
Performance automation 101 @LDNWebPerf MickMcGuinnessStephen Thair
 
WebPagetest - Good, Bad & Ugly
WebPagetest - Good, Bad & UglyWebPagetest - Good, Bad & Ugly
WebPagetest - Good, Bad & UglyAaron Peters
 
London Web Performance Meetup: Performance for mortal companies
London Web Performance Meetup: Performance for mortal companiesLondon Web Performance Meetup: Performance for mortal companies
London Web Performance Meetup: Performance for mortal companiesStrangeloop
 
Seatwave Web Peformance Optimisation Case Study
Seatwave Web Peformance Optimisation Case StudySeatwave Web Peformance Optimisation Case Study
Seatwave Web Peformance Optimisation Case StudyStephen Thair
 
Building high performing web pages
Building high performing web pagesBuilding high performing web pages
Building high performing web pagesNilesh Bafna
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixBruce Snyder
 
Building an HTML5 Video Player
Building an HTML5 Video PlayerBuilding an HTML5 Video Player
Building an HTML5 Video PlayerJim Jeffers
 
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?Katy Slemon
 
Beyond Breakpoints: Improving Performance for Responsive Sites
Beyond Breakpoints: Improving Performance for Responsive SitesBeyond Breakpoints: Improving Performance for Responsive Sites
Beyond Breakpoints: Improving Performance for Responsive SitesRakuten Group, Inc.
 
Web Page Test - Beyond the Basics
Web Page Test - Beyond the BasicsWeb Page Test - Beyond the Basics
Web Page Test - Beyond the BasicsAndy Davies
 
ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)
ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)
ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)Clément Wehrung
 
Nuts and Bolts of WebSocket Devoxx 2014
Nuts and Bolts of WebSocket Devoxx 2014Nuts and Bolts of WebSocket Devoxx 2014
Nuts and Bolts of WebSocket Devoxx 2014Arun Gupta
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsersjeresig
 
Leverage HTTP to deliver cacheable websites - Codemotion Rome 2018
Leverage HTTP to deliver cacheable websites - Codemotion Rome 2018Leverage HTTP to deliver cacheable websites - Codemotion Rome 2018
Leverage HTTP to deliver cacheable websites - Codemotion Rome 2018Thijs Feryn
 
Leverage HTTP to deliver cacheable websites - Thijs Feryn - Codemotion Rome 2018
Leverage HTTP to deliver cacheable websites - Thijs Feryn - Codemotion Rome 2018Leverage HTTP to deliver cacheable websites - Thijs Feryn - Codemotion Rome 2018
Leverage HTTP to deliver cacheable websites - Thijs Feryn - Codemotion Rome 2018Codemotion
 
Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)Nicholas Zakas
 
腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站areyouok
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 

What's hot (20)

Front End Performance
Front End PerformanceFront End Performance
Front End Performance
 
Front end performance optimization
Front end performance optimizationFront end performance optimization
Front end performance optimization
 
Performance automation 101 @LDNWebPerf MickMcGuinness
Performance automation 101 @LDNWebPerf MickMcGuinnessPerformance automation 101 @LDNWebPerf MickMcGuinness
Performance automation 101 @LDNWebPerf MickMcGuinness
 
WebPagetest - Good, Bad & Ugly
WebPagetest - Good, Bad & UglyWebPagetest - Good, Bad & Ugly
WebPagetest - Good, Bad & Ugly
 
London Web Performance Meetup: Performance for mortal companies
London Web Performance Meetup: Performance for mortal companiesLondon Web Performance Meetup: Performance for mortal companies
London Web Performance Meetup: Performance for mortal companies
 
Seatwave Web Peformance Optimisation Case Study
Seatwave Web Peformance Optimisation Case StudySeatwave Web Peformance Optimisation Case Study
Seatwave Web Peformance Optimisation Case Study
 
Building high performing web pages
Building high performing web pagesBuilding high performing web pages
Building high performing web pages
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMix
 
Building an HTML5 Video Player
Building an HTML5 Video PlayerBuilding an HTML5 Video Player
Building an HTML5 Video Player
 
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?
 
Beyond Breakpoints: Improving Performance for Responsive Sites
Beyond Breakpoints: Improving Performance for Responsive SitesBeyond Breakpoints: Improving Performance for Responsive Sites
Beyond Breakpoints: Improving Performance for Responsive Sites
 
Web Page Test - Beyond the Basics
Web Page Test - Beyond the BasicsWeb Page Test - Beyond the Basics
Web Page Test - Beyond the Basics
 
ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)
ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)
ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)
 
Nuts and Bolts of WebSocket Devoxx 2014
Nuts and Bolts of WebSocket Devoxx 2014Nuts and Bolts of WebSocket Devoxx 2014
Nuts and Bolts of WebSocket Devoxx 2014
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsers
 
Leverage HTTP to deliver cacheable websites - Codemotion Rome 2018
Leverage HTTP to deliver cacheable websites - Codemotion Rome 2018Leverage HTTP to deliver cacheable websites - Codemotion Rome 2018
Leverage HTTP to deliver cacheable websites - Codemotion Rome 2018
 
Leverage HTTP to deliver cacheable websites - Thijs Feryn - Codemotion Rome 2018
Leverage HTTP to deliver cacheable websites - Thijs Feryn - Codemotion Rome 2018Leverage HTTP to deliver cacheable websites - Thijs Feryn - Codemotion Rome 2018
Leverage HTTP to deliver cacheable websites - Thijs Feryn - Codemotion Rome 2018
 
Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)
 
腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 

Similar to Tuning web performance

High Performance Web Pages - 20 new best practices
High Performance Web Pages - 20 new best practicesHigh Performance Web Pages - 20 new best practices
High Performance Web Pages - 20 new best practicesStoyan Stefanov
 
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NETSilicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NETMats Bryntse
 
Front End Website Optimization
Front End Website OptimizationFront End Website Optimization
Front End Website OptimizationGerard Sychay
 
Life on the Edge with ESI
Life on the Edge with ESILife on the Edge with ESI
Life on the Edge with ESIKit Chan
 
Front-end optimisation & jQuery Internals
Front-end optimisation & jQuery InternalsFront-end optimisation & jQuery Internals
Front-end optimisation & jQuery InternalsArtur Cistov
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindSam Keen
 
Optimising Web Application Frontend
Optimising Web Application FrontendOptimising Web Application Frontend
Optimising Web Application Frontendtkramar
 
Frontend performance
Frontend performanceFrontend performance
Frontend performancesacred 8
 
Sandboxing JS and HTML. A lession Learned
Sandboxing JS and HTML. A lession LearnedSandboxing JS and HTML. A lession Learned
Sandboxing JS and HTML. A lession LearnedMinded Security
 
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考えるIt is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考えるSadaaki HIRAI
 
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5Sadaaki HIRAI
 
jQuery Tips Tricks Trivia
jQuery Tips Tricks TriviajQuery Tips Tricks Trivia
jQuery Tips Tricks TriviaCognizant
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application developmentzonathen
 
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterPractical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterDoris Chen
 

Similar to Tuning web performance (20)

High Performance Web Pages - 20 new best practices
High Performance Web Pages - 20 new best practicesHigh Performance Web Pages - 20 new best practices
High Performance Web Pages - 20 new best practices
 
Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations
 
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NETSilicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
 
Front End Website Optimization
Front End Website OptimizationFront End Website Optimization
Front End Website Optimization
 
Life on the Edge with ESI
Life on the Edge with ESILife on the Edge with ESI
Life on the Edge with ESI
 
Front-end optimisation & jQuery Internals
Front-end optimisation & jQuery InternalsFront-end optimisation & jQuery Internals
Front-end optimisation & jQuery Internals
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
 
Optimising Web Application Frontend
Optimising Web Application FrontendOptimising Web Application Frontend
Optimising Web Application Frontend
 
Frontend performance
Frontend performanceFrontend performance
Frontend performance
 
Sandboxing JS and HTML. A lession Learned
Sandboxing JS and HTML. A lession LearnedSandboxing JS and HTML. A lession Learned
Sandboxing JS and HTML. A lession Learned
 
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考えるIt is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
 
Sanjeev ghai 12
Sanjeev ghai 12Sanjeev ghai 12
Sanjeev ghai 12
 
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
 
前端概述
前端概述前端概述
前端概述
 
Front-end performances
Front-end performancesFront-end performances
Front-end performances
 
jQuery Tips Tricks Trivia
jQuery Tips Tricks TriviajQuery Tips Tricks Trivia
jQuery Tips Tricks Trivia
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application development
 
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterPractical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
 
High-Speed HTML5
High-Speed HTML5High-Speed HTML5
High-Speed HTML5
 
dJango
dJangodJango
dJango
 

More from George Ang

Wrapper induction construct wrappers automatically to extract information f...
Wrapper induction   construct wrappers automatically to extract information f...Wrapper induction   construct wrappers automatically to extract information f...
Wrapper induction construct wrappers automatically to extract information f...George Ang
 
Opinion mining and summarization
Opinion mining and summarizationOpinion mining and summarization
Opinion mining and summarizationGeorge Ang
 
Huffman coding
Huffman codingHuffman coding
Huffman codingGeorge Ang
 
Do not crawl in the dust 
different ur ls similar text
Do not crawl in the dust 
different ur ls similar textDo not crawl in the dust 
different ur ls similar text
Do not crawl in the dust 
different ur ls similar textGeorge Ang
 
大规模数据处理的那些事儿
大规模数据处理的那些事儿大规模数据处理的那些事儿
大规模数据处理的那些事儿George Ang
 
腾讯大讲堂02 休闲游戏发展的文化趋势
腾讯大讲堂02 休闲游戏发展的文化趋势腾讯大讲堂02 休闲游戏发展的文化趋势
腾讯大讲堂02 休闲游戏发展的文化趋势George Ang
 
腾讯大讲堂03 qq邮箱成长历程
腾讯大讲堂03 qq邮箱成长历程腾讯大讲堂03 qq邮箱成长历程
腾讯大讲堂03 qq邮箱成长历程George Ang
 
腾讯大讲堂04 im qq
腾讯大讲堂04 im qq腾讯大讲堂04 im qq
腾讯大讲堂04 im qqGeorge Ang
 
腾讯大讲堂05 面向对象应对之道
腾讯大讲堂05 面向对象应对之道腾讯大讲堂05 面向对象应对之道
腾讯大讲堂05 面向对象应对之道George Ang
 
腾讯大讲堂06 qq邮箱性能优化
腾讯大讲堂06 qq邮箱性能优化腾讯大讲堂06 qq邮箱性能优化
腾讯大讲堂06 qq邮箱性能优化George Ang
 
腾讯大讲堂07 qq空间
腾讯大讲堂07 qq空间腾讯大讲堂07 qq空间
腾讯大讲堂07 qq空间George Ang
 
腾讯大讲堂08 可扩展web架构探讨
腾讯大讲堂08 可扩展web架构探讨腾讯大讲堂08 可扩展web架构探讨
腾讯大讲堂08 可扩展web架构探讨George Ang
 
腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站George Ang
 
腾讯大讲堂01 移动qq产品发展历程
腾讯大讲堂01 移动qq产品发展历程腾讯大讲堂01 移动qq产品发展历程
腾讯大讲堂01 移动qq产品发展历程George Ang
 
腾讯大讲堂10 customer engagement
腾讯大讲堂10 customer engagement腾讯大讲堂10 customer engagement
腾讯大讲堂10 customer engagementGeorge Ang
 
腾讯大讲堂11 拍拍ce工作经验分享
腾讯大讲堂11 拍拍ce工作经验分享腾讯大讲堂11 拍拍ce工作经验分享
腾讯大讲堂11 拍拍ce工作经验分享George Ang
 
腾讯大讲堂14 qq直播(qq live) 介绍
腾讯大讲堂14 qq直播(qq live) 介绍腾讯大讲堂14 qq直播(qq live) 介绍
腾讯大讲堂14 qq直播(qq live) 介绍George Ang
 
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍George Ang
 
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍George Ang
 
腾讯大讲堂16 产品经理工作心得分享
腾讯大讲堂16 产品经理工作心得分享腾讯大讲堂16 产品经理工作心得分享
腾讯大讲堂16 产品经理工作心得分享George Ang
 

More from George Ang (20)

Wrapper induction construct wrappers automatically to extract information f...
Wrapper induction   construct wrappers automatically to extract information f...Wrapper induction   construct wrappers automatically to extract information f...
Wrapper induction construct wrappers automatically to extract information f...
 
Opinion mining and summarization
Opinion mining and summarizationOpinion mining and summarization
Opinion mining and summarization
 
Huffman coding
Huffman codingHuffman coding
Huffman coding
 
Do not crawl in the dust 
different ur ls similar text
Do not crawl in the dust 
different ur ls similar textDo not crawl in the dust 
different ur ls similar text
Do not crawl in the dust 
different ur ls similar text
 
大规模数据处理的那些事儿
大规模数据处理的那些事儿大规模数据处理的那些事儿
大规模数据处理的那些事儿
 
腾讯大讲堂02 休闲游戏发展的文化趋势
腾讯大讲堂02 休闲游戏发展的文化趋势腾讯大讲堂02 休闲游戏发展的文化趋势
腾讯大讲堂02 休闲游戏发展的文化趋势
 
腾讯大讲堂03 qq邮箱成长历程
腾讯大讲堂03 qq邮箱成长历程腾讯大讲堂03 qq邮箱成长历程
腾讯大讲堂03 qq邮箱成长历程
 
腾讯大讲堂04 im qq
腾讯大讲堂04 im qq腾讯大讲堂04 im qq
腾讯大讲堂04 im qq
 
腾讯大讲堂05 面向对象应对之道
腾讯大讲堂05 面向对象应对之道腾讯大讲堂05 面向对象应对之道
腾讯大讲堂05 面向对象应对之道
 
腾讯大讲堂06 qq邮箱性能优化
腾讯大讲堂06 qq邮箱性能优化腾讯大讲堂06 qq邮箱性能优化
腾讯大讲堂06 qq邮箱性能优化
 
腾讯大讲堂07 qq空间
腾讯大讲堂07 qq空间腾讯大讲堂07 qq空间
腾讯大讲堂07 qq空间
 
腾讯大讲堂08 可扩展web架构探讨
腾讯大讲堂08 可扩展web架构探讨腾讯大讲堂08 可扩展web架构探讨
腾讯大讲堂08 可扩展web架构探讨
 
腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站
 
腾讯大讲堂01 移动qq产品发展历程
腾讯大讲堂01 移动qq产品发展历程腾讯大讲堂01 移动qq产品发展历程
腾讯大讲堂01 移动qq产品发展历程
 
腾讯大讲堂10 customer engagement
腾讯大讲堂10 customer engagement腾讯大讲堂10 customer engagement
腾讯大讲堂10 customer engagement
 
腾讯大讲堂11 拍拍ce工作经验分享
腾讯大讲堂11 拍拍ce工作经验分享腾讯大讲堂11 拍拍ce工作经验分享
腾讯大讲堂11 拍拍ce工作经验分享
 
腾讯大讲堂14 qq直播(qq live) 介绍
腾讯大讲堂14 qq直播(qq live) 介绍腾讯大讲堂14 qq直播(qq live) 介绍
腾讯大讲堂14 qq直播(qq live) 介绍
 
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
 
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
 
腾讯大讲堂16 产品经理工作心得分享
腾讯大讲堂16 产品经理工作心得分享腾讯大讲堂16 产品经理工作心得分享
腾讯大讲堂16 产品经理工作心得分享
 

Recently uploaded

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 

Recently uploaded (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Tuning web performance

  • 1. Tuning Web Performance in Frontend Perspective Lin-Chieh Shangkuan (上官林傑) ericsk@gmail.com
  • 2. AGENDA The Impacts of Web Performance Development Tools Website Optimization Concepts References
  • 3. The Impact of Performance Longer response time from web server. Too many requests (css/javascript files, images, flashes, ...) Complicated DOM structure Inefficient JavaScript codes ....
  • 4. The Impact of Performance Longer response time from web server. Too many requests (css/javascript files, images, flashes, ...) Complicated DOM structure Inefficient JavaScript codes 80~90% time spent on the frontend
  • 6. Development Tools Firefox http://getfirefox.com/ Firebug http://getfirebug.com/ Page Speed (Firebug plugin) http://code.google.com/speed/page-speed/ Y!Slow http://developer.yahoo.com/yslow/
  • 7. Development Tools (cont) Chrome (Chromium/WebKit) Developer Tools http://www.chromium.org/devtools Install AMAP Latest Web Browsers e.g. IE8/9 (preview), Firefox 3.6/nightly, Safari 4/WebKit, Chrome/Chromium, Opera 10/10.5
  • 8. Firebug Console Debugging your JavaScript code. Use console object in your JavaScript code. Interactive in the console tab.
  • 10. Listen to Suggestions Follow the suggestions from PageSpeed (or Y!Slow)
  • 12. HTTP Overviews Request: GET /foo/bar.js HTTP/1.1 Host: example.com User-Agent: Mozilla/5.0 Response: HTTP/1.1 200 OK Content-Type: application/x-javascript Last-Modified: Mon, 15 Mar 2010 10:00:00 GMT Content-Length: 1234 (function(){ .....
  • 13. HTTP Reuqest Example $ telnet ajax.googleapis.com 80 Trying 74.125.153.95... Connected to googleapis-ajax.l.google.com. Escape character is '^]'. GET /ajax/libs/jquery/1.4.2/jquery.min.js HTTP/1.1 Host: ajax.googleapis.com User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; zh-TW; rv:1.9.2) Gecko/20100115 Firefox/3.6 GTB7.0 Accept-Encoding: gzip,deflate HTTP/1.1 200 OK Content-Type: text/javascript; charset=UTF-8 Last-Modified: Mon, 15 Feb 2010 23:30:12 GMT Date: Mon, 15 Mar 2010 08:39:18 GMT Expires: Tue, 15 Mar 2011 08:39:18 GMT Vary: Accept-Encoding X-Content-Type-Options: nosniff Server: sffe Content-Encoding: gzip Cache-Control: public, max-age=31536000 Age: 2497 Content-Length: 24678 X-XSS-Protection: 0 ;iw?F???+??m?@ə???v?I։/M???6???????$e???...
  • 14. Ways to Speed up the Website Optimize the backend processing e.g., PHP engine, database, .... Scaling Transfers Co-location, CDN, ... Reducing the browser's requests CSS sprites, expire headers, http compression... Optimizing the contents Defer loading, rearrangement, ... Efficient JavaScript development Improving the programming techs, ...
  • 15. Scaling Transfers Use CDN e.g., Akamai, Amazon S3, ... Pixnet experience: http://www.slideshare.net/gslin/using-cdn- to-improve-performance Reduce DNS Lookups Keep-Alive fewer domains Avoid Redirects Use Comet
  • 16. Scaling Transfers Sharding Dominant Domains browser HTTP/1.1 HTTP/1.0 IE6, 7 2 4 IE8 6 6 FF2 2 8 FF3 6 6 Saf 4 4 Chrome 6 6 Op 4 4 Connections per server
  • 18. HTTP Compression Modern browsers support HTTP compression -- to reduce the size of response content Gzip the static (html, css, js, ...) files Don't compress everything (e.g., jpg, png, pdf, ... they are already compressed) Check if the Accept-Encoding header has gzip or deflate value. Respond Content-Encoding: gzip header.
  • 19. HTTP Compression In Apache httpd server, use mod_gzip (httpd 1.3) or mod_deflate (httpd 2.x). [mod_deflate] AddOutputFilterByType DEFLATE text/html text/css application/x-javascript Problems: Proxy may cache uncompressed content Add Vary: Accept-Encoding header IE6 bug: Q312496, Q313712
  • 20. Make Fewer Requests CSS Sprites: Combine N icons into 1 bigger image. Reduce N requests info 1 request. Be careful of the arrangement of the icons sample: http://www.google.com.tw/images/nav_logo8.png tool: http://tw.spritegen.website-performance.org/ http://csssprites.com/ Combine CSS/JavaScript files Using Google Closure Compiler Apache: http://code.google.com/p/modconcat/ Lighttpd: http://code.google.com/p/lighttpd-mod-concat/ YUI Comobo Handler: http://yuiblog. com/blog/2008/07/16/combohandler/
  • 21. Make Fewer Requests Reduce Cookie size (or split domains) Inline images: using base64 encoding <img src="data:image/png;base64, xxxxx"> IE7/6 doesn't support this feature Useful in mobile browser Not only images: <frame src="data:text/html,%3Chtml%3E% 3Cbody%20style%3D%22background..."></frame>
  • 22. Using Expires Headers Use Expires header to tell the browser how long to keep the resource. Browser won't fetch the resource again until the expire time Apache mod_expires module can help setting expire time <FilesMatch ".(css|js|jpg|png)$"> ExpiresDefault "access plus 1 year" </FilesMatch> e.g., Expires: Fri, 25 Mar 2011 08:00:00 GMT Cache-Control header In stead of using a specified date, Cache-Control header shows HOW LONG the client should keep it e.g., Cache-Control: max-age=31536000 # cache 1 year
  • 23. Using Last-Modified Headers Use Last-Modified header to tell the browser the last modified time of the resource. [request] [request] GET /foo/bar.css HTTP/1.1 GET /foo/bar.css HTTP/1.1 .... ... If-Modified-Since: Thu, 25 Mar 2010 [response] 10:00:00 GMT HTTP/1.1 200 OK ... Content-Type: text/css Last-Modified: Thu, 25 Mar 2010 10: [response] 00:00 GMT+8 HTTP/1.1 304 Not Modified .... ... (empty response body)
  • 24. Configuring ETag ETag (Entity Tag) header tells browser which to cache How ETag works: read Wikipedia Problem: Not-the-same tag across different servers Apache: inode-size-timestamp IIS: timestamp:changenumber Solution: Set ETag manually Remove it. (in Apache) FileETag none
  • 25. Invalidates the Cached Resources If the static resources are cached, how to invalidate them? Use signature in filename ( /js/foo.AB32FDC.js ) Add query string ( /js/foo.js?20100325110000 )
  • 27. Minifying JavaScript Reduce the size of JavaScript files. Reduce the total response sizes. HTML, CSS files can be also compressed. Closure-compiler Web-based http://closure-compiler.appspot.com/ RESTful API http://code.google.com/closure/compiler/docs/api-ref.html Standalone executable Ofuscation Reduce the length of variables names Be careful the obfuscation method (e.g., eval cause performance degradation) Be careful the conflicts.
  • 28. Optimizing Images Using appropriate image format and remove redundant chunks in the image files. PNG8 (256 colors) is a good choice. Optimizing: Crushing PNGs pngcrush (http://pmt.sf.net/pngcrush/) Stripping JPEG metadata jpegtran (http://jpegclub.org/) Convert GIF to PNG ImageMagick Optimizing GIF animations gifsicle ( (http://www.lcdf.org/gifsicle/) Avoid image scaling
  • 29. Put Stylesheets on The Top Browser delays showing any visible components while it and user wait for the stylesheet at the bottom. Use <link> to include stylesheets @import MUST precede all other rules @import may cause blank white screen phenomenon (in IE)
  • 30. Put JavaScripts at The Bottom JavaScript blocks parallel downloads Put at top: the other components are delayed- loaded. defer attributes: Firefox still blocks other downloads
  • 31. Non-blocking Loading Scripts IE8 is the first browser that supports downloading scripts in parallel. Ways to load JavaScripts XHR Eval XHR Inject Script in iframe Inserting script DOM element document.write
  • 32. Non-blocking Loading Scripts Existing Busy Preserve Tech Parallel Diff Domain Scripts indicator Order Normal IE8, SF4 Y Y IE, SF4 IE, SF4 XHR Eval * N N SF, Ch XHR Injection * N Y SF, Ch Script in iframe * N N IE, FF, SF, Ch Script DOM * Y Y FF, SF, Ch FF, Op IE, SF4, Ch2, Script Defer Y Y * * FF3.1 IE, SF4, Ch2, document.write Y Y * * Op
  • 33. iframes iframes are heavy and block onload event. Use script DOM injection to insert ADs instead of iframes.
  • 35. Make JavaScript/CSS External Reusing components Cache the files Unobstrusive JavaScripts
  • 36. Simplifying CSS Selectors CSS selector policy: Rightmost-First Tips: Avoid * selector Don't qualify ID/CSS selectors Specific rules Avoid descendant selectors Avoid Tag > Child selectors Rely on inheritance
  • 37. Efficient JavaScript Tips Using className instead of modifying style attributes of a DOM element. [bad ] var foo = document.getElementById('foo'); foo.style.color = '#f00'; foo.style.fontWeight = 'bold'; [good] .highlight { color: #f00; font-weight: bold; } foo.className = 'highlight';
  • 38. Efficient JavaScript Tips (con'd) Appending a newly-created DOM element after modifying its attributes. (avoid reflows) [bad] var foo = document.createElement('div'); document.body.appendChild(foo); foo.innerHTML = 'Hello, world'; foo.className = 'hello'; [good] var foo = document.createElement('div'); foo.innerHTML = 'Hello, world'; foo.className = 'hello'; document.body.appendChild(foo);
  • 39. Efficient JavaScript Tips Using document fragment to create new contents. [bad] document.body.appendChild(createDivElement()); document.body.appendChild(createDivElement()); ... [good] var frag = document.createDocumentFragment(); frag.appendChild(createDivElement()); frag.appendChild(createDivElement()); .... document.body.appendChild(frag);
  • 40. Efficient JavaScript Tips Using array join instead of directly concatenate strings. [bad ] ] var a = 'Hel'; a += 'lo'; a += ', wor'; a += 'ld!'; [good] var buf = ['Hel']; buf.push('lo'); buf.push(', wor'); buf.push('ld!'); a = buf.join('');
  • 41. Efficient JavaScript Tips Faster trim method: (use simple regular expression) [bad] str.replace(/^s+|s+$/g, ''); [better] str.replace(/^s+/, '').replace(/^s+$/, ''); [much better] str = str.replace(/^s+/, ''); for (i = str.length - 1; i >=0; i--) { if (/S/.test(str.charAt(i))) { str = str.substring(0, i + 1); break; } }
  • 42. Efficient JavaScript Tips Use popular JavaScript frameworks. (e.g. jQuery)
  • 43. Misc.
  • 44. Responsive Web Applications Prefetching resources AJAX Avoid long-running scripts
  • 45. HTML5 http://whatwg.org/html5 Short tags: <!DOCTYPE html> <meta charset="UTF-8"> <script src="xxx.js">, <style>...</style> <script async ...> Application Cache (offline data) https://developer.mozilla.org/En/Offline_resources_in_Firefox http://www.whatwg.org/specs/web-apps/current- work/multipage/offline.html http://googlecode.blogspot.com/2009/04/gmail-for-mobile- html5-series-using.html WebStorage/WebDatabase API
  • 46. Mobile Web Mobile device has lower hardware-profile so that the web performance is more important! iPhone Safari/Android browser/Opera Mini likes HTML5 (w/ a little CSS3)
  • 48. Books High Performance Web Sites, O'Reilly Even Faster Web Sites
  • 49. Websites Let's Make the Web Faster (Google) http://code.google.com/speed Exceptional Performance (Yahoo!) http://developer.yahoo.com/performance/ High Performance Web Sites Blog http://www.stevesouders.com/blog/