•Too many requests (css/javascript files, images, flashes, ...) •Complicated DOM structure •Inefficient JavaScript codes 80~90% time spent on the frontend
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.
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/
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>
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
browser the last modified time of the resource. [request] GET /foo/bar.css HTTP/1.1 .... [response] HTTP/1.1 200 OK Content-Type: text/css Last-Modified: Thu, 25 Mar 2010 10: 00:00 GMT+8 .... [request] GET /foo/bar.css HTTP/1.1 ... If-Modified-Since: Thu, 25 Mar 2010 10:00:00 GMT ... [response] HTTP/1.1 304 Not Modified ... (empty response body)
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
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.
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)
indicator Preserve 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 Script Defer IE, SF4, Ch2, FF3.1 Y Y * * document.write IE, SF4, Ch2, Op Y Y * *
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('');