SlideShare uma empresa Scribd logo
1 de 99
High Performance Web Sites14 rules for faster-loading pages Parham Fazel Hooman Noroozinia Tosan Tech Talk 2011/06
Introduction
Exceptional Performance started in 2004 quantify and improve the performance of all Yahoo! products worldwide center of expertise build tools, analyze data gather, research, and evangelize best practices
Scope performance breaks into two categories response time efficiency current focus is response time of web products
Rough Cuts: now Hardcopy: Summer 2007 http://www.oreilly.com/catalog/9780596514211/
Steve Souders employer:Google Head Performance Engineer blog:http://stevesouders.com/blog/ Steve works at Google on web performance and open source initiatives. He previously served as Chief Performance Yahoo!.
Steve is the author of High Performance Web Sites and Even Faster Web Sites.  	He is the creator of YSlow, one of the top 25 of 2 billion Firefox add-ons.  	He's created many other performance tools and services including the HTTP Archive, Cuzillion, Jdrop, ControlJS, and Browserscope. He serves as co-chair of Velocity, the web performance and operations conference from O'Reilly, and is co-founder of the Firebug Working Group.  	He taught CS193H: High Performance Web Sites at Stanford University.
The Importance of Front-End Performance
percentage of time spent on the front-end Back-end vs. Front-end
The Performance Golden Rule 80-90% of the end-user response time is spent on the front-end. Start there. ,[object Object]
Simpler
Proven to work,[object Object]
Performance Research
perceived response time slowcrawlboringsnailstagnantunexceptionalyawnunresponsiveimpatientdelaymoderateblahsubduedragapatheticprolongslackloadsluggishsleepylateunexcitingreducedlagcomplex heavyunmemorableobscurewhy wait performance speed enjoyable urgentinstantaccelerateperceptionsnapachievement betterimproveaction pleasantpacequickpromoteswiftcoolmaximumdriveprompt advance fast hurryrushsatisfyingfeelexceptionalbriskrapid exciting what is the end user’s experience?
User Perception Usability and perception are important for performance. The user’s perception is more relevant than actual unload-to-onload response time. Definition of "user onload" is undefined or varies from one web page to the next.
http://yuiblog.com/blog/2006/11/28/performance-research-part-1/
80/20 Performance Rule Vilfredo Pareto:  80% of consequences come from 20% of causes Focus on the 20% that affects 80% of the end-user response time. Start at the front-end.
2 3 1 user re-requests www.yahoo.com user requests www.yahoo.com user requests other web pages Empty vs. Full Cache
2 3 1 user re-requests www.yahoo.com user requests www.yahoo.com user requests other web pages Empty vs. Full Cache with an empty cache
2 3 1 user re-requests www.yahoo.com user requests www.yahoo.com user requests other web pages Empty vs. Full Cache
Empty vs. Full Cache 2 1 user requests www.yahoo.com user requests other web pages 3 user re-requests www.yahoo.com Expires header with a full cache
Empty vs. Full Cache 						   empty cache 							2.4 seconds 						   full cache 							0.9 seconds 83% fewer bytes 90% fewer HTTP requests
How much does this benefit our users? It depends on how many users have components in cache. ,[object Object],	* “Empty cache” means the browser has to request the componentsinstead of pulling them from the browser disk cache. ,[object Object],[object Object]
}1 px Add a new image to your page <img src="image/blank.gif" height="1" width="1"/> with the following response headers: Expires: Thu, 15 Apr 2004 20:00:00 GMT Last-Modified: Wed, 28 Sep 2006 23:49:57 GMT Browser Cache Experiment
Browser Cache Experiment Requests from the browser will have one of these response status codes: 200 – The browser does not have the image in its cache. 304 – The browser has the image in its cache, but needs to verify the last modified date.
Browser Cache Experiment }1 px
Surprising Results users withempty cache page views withempty cache 40-60%  ~20%
Experiment Takeaways Keep in mind the empty cache user experience. It might be more prevalent than you think! Use different techniques to optimize full versus empty cache experience.
http://yuiblog.com/blog/2007/03/01/performance-research-part-3
1 user requests www.yahoo.com HTTP Quick Review HTTP response header sent by the web server: HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 Set-Cookie: C=abcdefghijklmnopqrstuvwxyz; domain=.yahoo.com
1 user requests www.yahoo.com HTTP Quick Review 2 user requests finance.yahoo.com HTTP request header sent by the browser: GET / HTTP/1.1 Host: finance.yahoo.com User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; … Cookie: C=abcdefghijklmnopqrstuvwxyz;
3 1 user requests autos.yahoo.com user requests www.yahoo.com HTTP Quick Review HTTP request header sent by the browser: GET / HTTP/1.1 Host: autos.yahoo.com User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; … Cookie: C=abcdefghijklmnopqrstuvwxyz;
4 1 user requests mail.yahoo.com user requests www.yahoo.com HTTP Quick Review HTTP request header sent by the browser: GET / HTTP/1.1 Host: mail.yahoo.com User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; … Cookie: C=abcdefghijklmnopqrstuvwxyz;
5 1 user requests tech.yahoo.com user requests www.yahoo.com HTTP Quick Review HTTP request header sent by the browser: GET / HTTP/1.1 Host: tech.yahoo.com User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; … Cookie: C=abcdefghijklmnopqrstuvwxyz;
Impact of Cookies on Response Time dialup users 80 ms delay keep sizes low
.yahoo.com cookie sizes
Analysis of Cookie Sizes across the Web
Experiment Takeaways eliminate unnecessary cookies keep cookie sizes low set cookies at appropriate domain level set Expires date appropriately earlier date or none removes cookie sooner
http://yuiblog.com/blog/2007/04/11/performance-research-part-4/
Parallel Downloads GIF GIF GIF GIF GIF GIF Two components in parallel per hostname HTTP/1.1
Parallel Downloads Two in parallel Four in parallel Eight in parallel
Maximizing Parallel Downloads response time (seconds) aliases
Maximizing Parallel Downloads response time (seconds) aliases
Maximizing Parallel Downloads response time (seconds) aliases
Maximizing Parallel Downloads response time (seconds) rule of thumb: use at least two but no more than four aliases
Experiment Takeaways consider the effects of CPU thrashing DNS lookup times vary across ISPs and geographic locations domain names may not be cached
Summary What the 80/20 Rule Tells Us about Reducing HTTP Requests http://yuiblog.com/blog/2007/04/11/performance-research-part-4/ Browser Cache Usage – Exposed! http://yuiblog.com/blog/2007/01/04/performance-research-part-2/ When the Cookie Crumbles http://yuiblog.com/blog/2007/01/04/performance-research-part-2/ Maximizing Parallel Downloads in the Carpool Lane http://yuiblog.com/blog/2007/04/11/performance-research-part-4/
14 Rules
14 Rules Make fewer HTTP requests Use a CDN Add an Expires header Gzip components Put CSS at the top Move JS to the bottom Avoid CSS expressions Make JS and CSS external Reduce DNS lookups Minify JS Avoid redirects Remove duplicate scripts Turn off ETags Make AJAX cacheable and small
Rule 1: Make fewer HTTP requests image maps CSS sprites inline images combined scripts, combined stylesheets
Image maps server-side <a href="navbar.cgi"><img ismap src="imagemap.gif"></a> -> http://.../navbar.cgi?127,13 client-side – preferred <img usemap="#map1" border=0 src="/images/imagemap.gif"> <map name="map1">   <area shape="rect" coords="0,0,31,31" href="home.html" title="Home">    … </map> drawbacks: must be contiguous defining area coordinates – tedious, errors http://www.w3.org/TR/html401/struct/objects.html#h-13.6
CSS Sprites – Preferred <span style="   background-image: url('sprites.gif');   background-position: -260px -90px;"> </span> size of combined image is less not supported in Opera 6 http://alistapart.com/articles/sprites
Inline Images data: URL scheme data:[<mediatype>][;base64],<data> <IMG ALT=”Red Star” SRC="data:image/gif;base64,R0lGODlhDAAMALMLAPN8ffBiYvWWlvrKy/FvcPewsO9VVfajo+w6O/zl5estLv/8/AAAAAAAAAAAAAAAACH5BAEAAAsALAAAAAAMAAwAAAQzcElZyryTEHyTUgknHd9xGV+qKsYirKkwDYiKDBiatt2H1KBLQRFIJAIKywRgmhwAIlEEADs="> not supported in IE avoid increasing size of HTML pages: put inline images in cached stylesheets http://tools.ietf.org/html/rfc2397
Combined Scripts, Combined Stylesheets
Combined Scripts,Combined Stylesheets combining six scripts into one eliminates five HTTP requests challenges:  develop as separate modules number of possible combinations vs. loading more than needed maximize browser cache one solution: dynamically combine and cache
Rule 2: Use a CDN distribute your static content before distributing your dynamic content
Rule 3: Add an Expires header  not just for images
Rule 4: Gzip components  you can affect users' download times 90%+ of browsers support compression
Gzip compresses more Gzip supported in more browsers Gzip vs. Deflate
Gzip: not just for HTML gzip scripts, stylesheets, XML, JSON (not images, PDF)
Gzip Configuration  Apache 2.x: mod_deflate AddOutputFilterByType DEFLATE text/html text/css application/x-javascript HTTP request Accept-Encoding: gzip, deflate HTTP response Content-Encoding: gzip Vary: Accept-Encoding needed for proxies
Gzip Edge Cases  <1% of browsers have problems with gzip IE 5.5:      http://support.microsoft.com/default.aspx?scid=kb;en-us;Q313712 IE 6.0:     http://support.microsoft.com/default.aspx?scid=kb;en-us;Q31249 Netscape 3.x, 4.x     http://www.schroepl.net/projekte/mod_gzip/browser.htm consider adding Cache-Control: Private remove ETags (Rule 13) hard to diagnose; problem getting smaller
Rule 5: Put CSS at the top  stylesheets block rendering in IE http://stevesouders.com/examples/css-bottom.php solution: put stylesheets in HEAD (per spec) avoids Flash of Unstyled Content use LINK (not @import)
Slowest is Fastest
Rule 6: Move scripts to the bottom  scripts block parallel downloads across all hostnames scripts block rendering of everything below them in the page IE and FF http://stevesouders.com/examples/js-middle.php
Rule 6: Move scripts to the bottom  script defer attribute is not a solution blocks rendering and downloads in FF slight blocking in IE solution: move them as low in the page as possible
Rule 7: Avoid CSS expressions  used to set CSS properties dynamically in IE width: expression(    document.body.clientWidth < 600 ?    “600px” : “auto” ); problem: expressions execute many times mouse move, key press, resize, scroll, etc. http://stevesouders.com/examples/expression-counter.php
One-Time Expressions expression overwrites itself <style> P {     background-color: expression(altBgcolor(this)); } </style> <script> function altBgcolor(elem) {     elem.style.backgroundColor = (new Date()).getHours()%2 ? "#F08A00" : "#B8D4FF"; } </script>
Event Handlers tie behavior to (fewer) specific events window.onresize = setMinWidth; function setMinWidth() { varaElements =                   document.getElementsByTagName("p");     for ( vari = 0; i < aElements.length; i++ ) { aElements[i].runtimeStyle.width = (  document.body.clientWidth<600 ?             "600px" : "auto" );     } }
Rule 8: Make JS and CSS external  inline: HTML document is bigger external: more HTTP requests, but cached variables page views per user (per session) empty vs. full cache stats component re-use external is typically better home pages may be an exception
Post-Onload Download inline in front page download external files after onload window.onload = downloadComponents; function downloadComponents() {     var elem = document.createElement("script");     elem.src = "http://.../file1.js";     document.body.appendChild(elem);     ... } speeds up secondary pages
Dynamic Inlining start with post-onload download set cookie after components downloaded server-side:  if cookie, use external else, do inline with post-onload download cookie expiration date is key speeds up all pages
Rule 9: Reduce DNS lookups  typically 20-120 ms block parallel downloads OS and browser both have DNS caches
TTL (Time To Live) TTL – how long record can be cached browser settings override TTL
Browser DNS Cache IE DnsCacheTimeout: 30 minutes KeepAliveTimeout: 1 minute ServerInfoTimeout: 2 minutes Firefox network.dnsCacheExpiration: 1 minute network.dnsCacheEntries: 20 network.http.keep-alive.timeout: 5 minutes Fasterfox: 1 hour, 512 entries, 30 seconds
Reducing DNS Lookups fewer hostnames – 2-4 keep-alive
Rule 10: Minify JavaScript minify inline scripts, too
Minify vs. Obfuscate minify – it's safer http://crockford.com/javascript/jsmin http://dojotoolkit.org/docs/shrinksafe
Rule 11: Avoid redirects 3xx status codes – mostly 301 and 302 HTTP/1.1 301 Moved Permanently Location: http://stevesouders.com/newuri add Expires headers to cache redirects worst form of blocking http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
Redirects
Avoid Redirects missing trailing slash http://astrology.yahoo.com/astrology use Alias or DirectorySlash mod_rewrite CNAMEs log referer – track internal links outbound links – harder beacons – beware of race condition XHR – bail at readyState 2
Rule 12: Remove duplicate scripts hurts performance extra HTTP requests (IE only) extra executions atypical? 2 of 10 top sites contain duplicate scripts team size, # of scripts
Script Insertion Functions <?php function insertScript($jsfile) {     if ( alreadyInserted($jsfile) ) { return; }     pushInserted($jsfile);     if ( hasDependencies($jsfile) ) {         $dependencies = getDependencies($jsfile);         for ( $i = 0; $i < count($dependencies); $i++ ) {             insertScript($dependencies[$i]);         }     }     echo '<script type="text/javascript" src="' .           getVersion($jsfile) . '"></script>"; } ?>
Rule 13: Turn off ETags unique identifier returned in response ETag: "c8897e-aee-4165acf0" Last-Modified: Thu, 07 Oct 2004 20:54:08 GMT used in conditional GET requests If-None-Match: "c8897e-aee-4165acf0" If-Modified-Since: Thu, 07 Oct 2004 20:54:08 GMT if ETag doesn't match, can't send 304
The Problem with ETags ETag for a single entity is always different across servers ETag format Apache: inode-size-timestamp IIS: Filetimestamp:ChangeNumber Sites with >1 server return too few 304s (n-1)/n Remove them Apache: FileETag none IIS: http://support.microsoft.com/kb/922703/
Rule 14: Make AJAX cacheable and small XHR, JSON, iframe, dynamic scripts can still be cached, minified, and gzipped a personalized response should still be cacheable by that person
AJAX Example: Yahoo! Mail Beta address book XML request -> GET /yab/[...]&r=0.5289571053069156 HTTP/1.1   Host: us.xxx.mail.yahoo.com ← HTTP/1.1 200 OK   Date: Thu, 12 Apr 2007 19:39:09 GMT   Cache-Control: private,max-age=0   Last-Modified: Sat, 31 Mar 2007 01:17:17 GMT   Content-Type: text/xml; charset=utf-8   Content-Encoding: gzip address book changes infrequently cache it; add last-modified-time in URL
Live Analysis
IBM Page Detailer packet sniffer Windows only IE, FF, any .exe c:indowsd_WS2s.ini Executable=(NETSCAPE.EXE),(NETSCP6.EXE),(firefox.exe) free trial, $300 license http://alphaworks.ibm.com/tech/pagedetailer
http://alphaworks.ibm.com/tech/pagedetailer
Fasterfox measures load time of pages alters config settings for faster loading Firefox extension free http://fasterfox.mozdev.org/
LiveHTTPHeaders view HTTP headers Firefox extension free http://livehttpheaders.mozdev.org/
Firebug web development evolved inspect and edit HTML tweak and visualize CSS debug and profile JavaScript monitor network activity (caveat) Firefox extension free http://getfirebug.com/
http://getfirebug.com/
YSlow performance lint tool grades web pages for each rule Firefox extension Yahoo! internal tool
Conclusion
Takeaways focus on the front-end harvest the low-hanging fruit you do control user response times LOFNO – be an advocate for your users
Links book: http://www.oreilly.com/catalog/9780596514211/ examples: http://stevesouders.com/examples/ image maps: http://www.w3.org/TR/html401/struct/objects.html#h-13.6 CSS sprites: http://alistapart.com/articles/sprites inline images: http://tools.ietf.org/html/rfc2397 jsmin: http://crockford.com/javascript/jsmin dojo compressor: http://dojotoolkit.org/docs/shrinksafe HTTP status codes: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html IBM Page Detailer: http://alphaworks.ibm.com/tech/pagedetailer Fasterfox: http://fasterfox.mozdev.org/ LiveHTTPHeaders: http://livehttpheaders.mozdev.org/ Firebug: http://getfirebug.com/ YUIBlog: http://yuiblog.com/blog/2006/11/28/performance-research-part-1/ http://yuiblog.com/blog/2007/01/04/performance-research-part-2/ http://yuiblog.com/blog/2007/03/01/performance-research-part-3/ http://yuiblog.com/blog/2007/04/11/performance-research-part-4/ YDN: http://developer.yahoo.net/blog/archives/2007/03/high_performanc.html http://developer.yahoo.net/blog/archives/2007/04/rule_1_make_few.html

Mais conteúdo relacionado

Mais procurados

A Holistic View of Website Performance
A Holistic View of Website PerformanceA Holistic View of Website Performance
A Holistic View of Website PerformanceRene Churchill
 
How I learned to stop worrying and love the .htaccess file
How I learned to stop worrying and love the .htaccess fileHow I learned to stop worrying and love the .htaccess file
How I learned to stop worrying and love the .htaccess fileRoxana Stingu
 
Browser Wars Episode 1: The Phantom Menace
Browser Wars Episode 1: The Phantom MenaceBrowser Wars Episode 1: The Phantom Menace
Browser Wars Episode 1: The Phantom MenaceNicholas Zakas
 
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
 
Web Client Performance
Web Client PerformanceWeb Client Performance
Web Client PerformanceHerea Adrian
 
@media - Even Faster Web Sites
@media - Even Faster Web Sites@media - Even Faster Web Sites
@media - Even Faster Web SitesSteve Souders
 
Web 2.0 Expo: Even Faster Web Sites
Web 2.0 Expo: Even Faster Web SitesWeb 2.0 Expo: Even Faster Web Sites
Web 2.0 Expo: Even Faster Web SitesSteve Souders
 
Web Page Test - Beyond the Basics
Web Page Test - Beyond the BasicsWeb Page Test - Beyond the Basics
Web Page Test - Beyond the BasicsAndy Davies
 
10 Tips to make your Website lightning-fast - SMX Stockholm 2012
10 Tips to make your Website lightning-fast - SMX Stockholm 201210 Tips to make your Website lightning-fast - SMX Stockholm 2012
10 Tips to make your Website lightning-fast - SMX Stockholm 2012Bastian Grimm
 
The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014
The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014
The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014Bastian Grimm
 
The Case for HTTP/2 - Internetdagarna 2015 - Stockholm
The Case for HTTP/2  - Internetdagarna 2015 - StockholmThe Case for HTTP/2  - Internetdagarna 2015 - Stockholm
The Case for HTTP/2 - Internetdagarna 2015 - StockholmAndy Davies
 
Is your website's speed letting you down?
Is your website's speed letting you down?Is your website's speed letting you down?
Is your website's speed letting you down?Ray Krzeminski
 
Web Performance 101
Web Performance 101Web Performance 101
Web Performance 101Uri Lavi
 
How fast are we going now?
How fast are we going now?How fast are we going now?
How fast are we going now?Steve Souders
 
What does the browser pre-loader do?
What does the browser pre-loader do?What does the browser pre-loader do?
What does the browser pre-loader do?Andy Davies
 
High Performance Mobile (SF/SV Web Perf)
High Performance Mobile (SF/SV Web Perf)High Performance Mobile (SF/SV Web Perf)
High Performance Mobile (SF/SV Web Perf)Steve Souders
 
Prebrowsing - Velocity NY 2013
Prebrowsing - Velocity NY 2013Prebrowsing - Velocity NY 2013
Prebrowsing - Velocity NY 2013Steve Souders
 
High Performance HTML5 (SF HTML5 UG)
High Performance HTML5 (SF HTML5 UG)High Performance HTML5 (SF HTML5 UG)
High Performance HTML5 (SF HTML5 UG)Steve Souders
 

Mais procurados (20)

A Holistic View of Website Performance
A Holistic View of Website PerformanceA Holistic View of Website Performance
A Holistic View of Website Performance
 
How I learned to stop worrying and love the .htaccess file
How I learned to stop worrying and love the .htaccess fileHow I learned to stop worrying and love the .htaccess file
How I learned to stop worrying and love the .htaccess file
 
Browser Wars Episode 1: The Phantom Menace
Browser Wars Episode 1: The Phantom MenaceBrowser Wars Episode 1: The Phantom Menace
Browser Wars Episode 1: The Phantom Menace
 
Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)
 
Web Client Performance
Web Client PerformanceWeb Client Performance
Web Client Performance
 
@media - Even Faster Web Sites
@media - Even Faster Web Sites@media - Even Faster Web Sites
@media - Even Faster Web Sites
 
Web 2.0 Expo: Even Faster Web Sites
Web 2.0 Expo: Even Faster Web SitesWeb 2.0 Expo: Even Faster Web Sites
Web 2.0 Expo: Even Faster Web Sites
 
Keep the Web Fast
Keep the Web FastKeep the Web Fast
Keep the Web Fast
 
Web Page Test - Beyond the Basics
Web Page Test - Beyond the BasicsWeb Page Test - Beyond the Basics
Web Page Test - Beyond the Basics
 
10 Tips to make your Website lightning-fast - SMX Stockholm 2012
10 Tips to make your Website lightning-fast - SMX Stockholm 201210 Tips to make your Website lightning-fast - SMX Stockholm 2012
10 Tips to make your Website lightning-fast - SMX Stockholm 2012
 
The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014
The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014
The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014
 
The Case for HTTP/2 - Internetdagarna 2015 - Stockholm
The Case for HTTP/2  - Internetdagarna 2015 - StockholmThe Case for HTTP/2  - Internetdagarna 2015 - Stockholm
The Case for HTTP/2 - Internetdagarna 2015 - Stockholm
 
Is your website's speed letting you down?
Is your website's speed letting you down?Is your website's speed letting you down?
Is your website's speed letting you down?
 
Web Performance 101
Web Performance 101Web Performance 101
Web Performance 101
 
How fast are we going now?
How fast are we going now?How fast are we going now?
How fast are we going now?
 
Design+Performance
Design+PerformanceDesign+Performance
Design+Performance
 
What does the browser pre-loader do?
What does the browser pre-loader do?What does the browser pre-loader do?
What does the browser pre-loader do?
 
High Performance Mobile (SF/SV Web Perf)
High Performance Mobile (SF/SV Web Perf)High Performance Mobile (SF/SV Web Perf)
High Performance Mobile (SF/SV Web Perf)
 
Prebrowsing - Velocity NY 2013
Prebrowsing - Velocity NY 2013Prebrowsing - Velocity NY 2013
Prebrowsing - Velocity NY 2013
 
High Performance HTML5 (SF HTML5 UG)
High Performance HTML5 (SF HTML5 UG)High Performance HTML5 (SF HTML5 UG)
High Performance HTML5 (SF HTML5 UG)
 

Semelhante a High Performance Websites

腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站topgeek
 
腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站George Ang
 
Csdn Drdobbs Tenni Theurer Yahoo
Csdn Drdobbs Tenni Theurer YahooCsdn Drdobbs Tenni Theurer Yahoo
Csdn Drdobbs Tenni Theurer Yahooguestb1b95b
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax ApplicationsSiarhei Barysiuk
 
Heavy Web Optimization: Frontend
Heavy Web Optimization: FrontendHeavy Web Optimization: Frontend
Heavy Web Optimization: FrontendVõ Duy Tuấn
 
Fast and Easy Website Tuneups
Fast and Easy Website TuneupsFast and Easy Website Tuneups
Fast and Easy Website TuneupsJeff Wisniewski
 
Does This Theme Make My Website Look Fat? (Wordcamp SLC 2013)
Does This Theme Make My Website Look Fat? (Wordcamp SLC 2013)Does This Theme Make My Website Look Fat? (Wordcamp SLC 2013)
Does This Theme Make My Website Look Fat? (Wordcamp SLC 2013)Adam Dunford
 
Internet Explorer 8 for Developers by Christian Thilmany
Internet Explorer 8 for Developers by Christian ThilmanyInternet Explorer 8 for Developers by Christian Thilmany
Internet Explorer 8 for Developers by Christian ThilmanyChristian Thilmany
 
High performance website
High performance websiteHigh performance website
High performance websiteChamnap Chhorn
 
Frontend performance
Frontend performanceFrontend performance
Frontend performancesacred 8
 
10 things you can do to speed up your web app today stir trek edition
10 things you can do to speed up your web app today   stir trek edition10 things you can do to speed up your web app today   stir trek edition
10 things you can do to speed up your web app today stir trek editionChris Love
 
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...The 5 most common reasons for a slow WordPress site and how to fix them – ext...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...Otto Kekäläinen
 
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...John McCaffrey
 
Windy cityrails performance_tuning
Windy cityrails performance_tuningWindy cityrails performance_tuning
Windy cityrails performance_tuningJohn McCaffrey
 
GDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
GDD Japan 2009 - Designing OpenSocial Apps For Speed and ScaleGDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
GDD Japan 2009 - Designing OpenSocial Apps For Speed and ScalePatrick Chanezon
 
Web Performance Optimierung - DWX13
Web Performance Optimierung - DWX13Web Performance Optimierung - DWX13
Web Performance Optimierung - DWX13Walter Ebert
 
Widget Summit 2008
Widget Summit 2008Widget Summit 2008
Widget Summit 2008Volkan Unsal
 
Decoding the Web
Decoding the WebDecoding the Web
Decoding the Webnewcircle
 

Semelhante a High Performance Websites (20)

腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站
 
腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站
 
Csdn Drdobbs Tenni Theurer Yahoo
Csdn Drdobbs Tenni Theurer YahooCsdn Drdobbs Tenni Theurer Yahoo
Csdn Drdobbs Tenni Theurer Yahoo
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax Applications
 
High-Speed HTML5
High-Speed HTML5High-Speed HTML5
High-Speed HTML5
 
Speed = $$$
Speed = $$$Speed = $$$
Speed = $$$
 
Heavy Web Optimization: Frontend
Heavy Web Optimization: FrontendHeavy Web Optimization: Frontend
Heavy Web Optimization: Frontend
 
Fast and Easy Website Tuneups
Fast and Easy Website TuneupsFast and Easy Website Tuneups
Fast and Easy Website Tuneups
 
Does This Theme Make My Website Look Fat? (Wordcamp SLC 2013)
Does This Theme Make My Website Look Fat? (Wordcamp SLC 2013)Does This Theme Make My Website Look Fat? (Wordcamp SLC 2013)
Does This Theme Make My Website Look Fat? (Wordcamp SLC 2013)
 
Internet Explorer 8 for Developers by Christian Thilmany
Internet Explorer 8 for Developers by Christian ThilmanyInternet Explorer 8 for Developers by Christian Thilmany
Internet Explorer 8 for Developers by Christian Thilmany
 
High performance website
High performance websiteHigh performance website
High performance website
 
Frontend performance
Frontend performanceFrontend performance
Frontend performance
 
10 things you can do to speed up your web app today stir trek edition
10 things you can do to speed up your web app today   stir trek edition10 things you can do to speed up your web app today   stir trek edition
10 things you can do to speed up your web app today stir trek edition
 
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...The 5 most common reasons for a slow WordPress site and how to fix them – ext...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
 
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
 
Windy cityrails performance_tuning
Windy cityrails performance_tuningWindy cityrails performance_tuning
Windy cityrails performance_tuning
 
GDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
GDD Japan 2009 - Designing OpenSocial Apps For Speed and ScaleGDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
GDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
 
Web Performance Optimierung - DWX13
Web Performance Optimierung - DWX13Web Performance Optimierung - DWX13
Web Performance Optimierung - DWX13
 
Widget Summit 2008
Widget Summit 2008Widget Summit 2008
Widget Summit 2008
 
Decoding the Web
Decoding the WebDecoding the Web
Decoding the Web
 

Último

Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsPooky Knightsmith
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptxJonalynLegaspi2
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1GloryAnnCastre1
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptxDhatriParmar
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 

Último (20)

Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young minds
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptx
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 

High Performance Websites

  • 1. High Performance Web Sites14 rules for faster-loading pages Parham Fazel Hooman Noroozinia Tosan Tech Talk 2011/06
  • 3. Exceptional Performance started in 2004 quantify and improve the performance of all Yahoo! products worldwide center of expertise build tools, analyze data gather, research, and evangelize best practices
  • 4. Scope performance breaks into two categories response time efficiency current focus is response time of web products
  • 5. Rough Cuts: now Hardcopy: Summer 2007 http://www.oreilly.com/catalog/9780596514211/
  • 6. Steve Souders employer:Google Head Performance Engineer blog:http://stevesouders.com/blog/ Steve works at Google on web performance and open source initiatives. He previously served as Chief Performance Yahoo!.
  • 7. Steve is the author of High Performance Web Sites and Even Faster Web Sites. He is the creator of YSlow, one of the top 25 of 2 billion Firefox add-ons. He's created many other performance tools and services including the HTTP Archive, Cuzillion, Jdrop, ControlJS, and Browserscope. He serves as co-chair of Velocity, the web performance and operations conference from O'Reilly, and is co-founder of the Firebug Working Group. He taught CS193H: High Performance Web Sites at Stanford University.
  • 8. The Importance of Front-End Performance
  • 9. percentage of time spent on the front-end Back-end vs. Front-end
  • 10.
  • 12.
  • 14. perceived response time slowcrawlboringsnailstagnantunexceptionalyawnunresponsiveimpatientdelaymoderateblahsubduedragapatheticprolongslackloadsluggishsleepylateunexcitingreducedlagcomplex heavyunmemorableobscurewhy wait performance speed enjoyable urgentinstantaccelerateperceptionsnapachievement betterimproveaction pleasantpacequickpromoteswiftcoolmaximumdriveprompt advance fast hurryrushsatisfyingfeelexceptionalbriskrapid exciting what is the end user’s experience?
  • 15. User Perception Usability and perception are important for performance. The user’s perception is more relevant than actual unload-to-onload response time. Definition of "user onload" is undefined or varies from one web page to the next.
  • 17. 80/20 Performance Rule Vilfredo Pareto: 80% of consequences come from 20% of causes Focus on the 20% that affects 80% of the end-user response time. Start at the front-end.
  • 18. 2 3 1 user re-requests www.yahoo.com user requests www.yahoo.com user requests other web pages Empty vs. Full Cache
  • 19. 2 3 1 user re-requests www.yahoo.com user requests www.yahoo.com user requests other web pages Empty vs. Full Cache with an empty cache
  • 20. 2 3 1 user re-requests www.yahoo.com user requests www.yahoo.com user requests other web pages Empty vs. Full Cache
  • 21. Empty vs. Full Cache 2 1 user requests www.yahoo.com user requests other web pages 3 user re-requests www.yahoo.com Expires header with a full cache
  • 22. Empty vs. Full Cache empty cache 2.4 seconds full cache 0.9 seconds 83% fewer bytes 90% fewer HTTP requests
  • 23.
  • 24. }1 px Add a new image to your page <img src="image/blank.gif" height="1" width="1"/> with the following response headers: Expires: Thu, 15 Apr 2004 20:00:00 GMT Last-Modified: Wed, 28 Sep 2006 23:49:57 GMT Browser Cache Experiment
  • 25. Browser Cache Experiment Requests from the browser will have one of these response status codes: 200 – The browser does not have the image in its cache. 304 – The browser has the image in its cache, but needs to verify the last modified date.
  • 27. Surprising Results users withempty cache page views withempty cache 40-60% ~20%
  • 28. Experiment Takeaways Keep in mind the empty cache user experience. It might be more prevalent than you think! Use different techniques to optimize full versus empty cache experience.
  • 30. 1 user requests www.yahoo.com HTTP Quick Review HTTP response header sent by the web server: HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 Set-Cookie: C=abcdefghijklmnopqrstuvwxyz; domain=.yahoo.com
  • 31. 1 user requests www.yahoo.com HTTP Quick Review 2 user requests finance.yahoo.com HTTP request header sent by the browser: GET / HTTP/1.1 Host: finance.yahoo.com User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; … Cookie: C=abcdefghijklmnopqrstuvwxyz;
  • 32. 3 1 user requests autos.yahoo.com user requests www.yahoo.com HTTP Quick Review HTTP request header sent by the browser: GET / HTTP/1.1 Host: autos.yahoo.com User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; … Cookie: C=abcdefghijklmnopqrstuvwxyz;
  • 33. 4 1 user requests mail.yahoo.com user requests www.yahoo.com HTTP Quick Review HTTP request header sent by the browser: GET / HTTP/1.1 Host: mail.yahoo.com User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; … Cookie: C=abcdefghijklmnopqrstuvwxyz;
  • 34. 5 1 user requests tech.yahoo.com user requests www.yahoo.com HTTP Quick Review HTTP request header sent by the browser: GET / HTTP/1.1 Host: tech.yahoo.com User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; … Cookie: C=abcdefghijklmnopqrstuvwxyz;
  • 35. Impact of Cookies on Response Time dialup users 80 ms delay keep sizes low
  • 37. Analysis of Cookie Sizes across the Web
  • 38. Experiment Takeaways eliminate unnecessary cookies keep cookie sizes low set cookies at appropriate domain level set Expires date appropriately earlier date or none removes cookie sooner
  • 40. Parallel Downloads GIF GIF GIF GIF GIF GIF Two components in parallel per hostname HTTP/1.1
  • 41. Parallel Downloads Two in parallel Four in parallel Eight in parallel
  • 42. Maximizing Parallel Downloads response time (seconds) aliases
  • 43. Maximizing Parallel Downloads response time (seconds) aliases
  • 44. Maximizing Parallel Downloads response time (seconds) aliases
  • 45. Maximizing Parallel Downloads response time (seconds) rule of thumb: use at least two but no more than four aliases
  • 46. Experiment Takeaways consider the effects of CPU thrashing DNS lookup times vary across ISPs and geographic locations domain names may not be cached
  • 47. Summary What the 80/20 Rule Tells Us about Reducing HTTP Requests http://yuiblog.com/blog/2007/04/11/performance-research-part-4/ Browser Cache Usage – Exposed! http://yuiblog.com/blog/2007/01/04/performance-research-part-2/ When the Cookie Crumbles http://yuiblog.com/blog/2007/01/04/performance-research-part-2/ Maximizing Parallel Downloads in the Carpool Lane http://yuiblog.com/blog/2007/04/11/performance-research-part-4/
  • 49. 14 Rules Make fewer HTTP requests Use a CDN Add an Expires header Gzip components Put CSS at the top Move JS to the bottom Avoid CSS expressions Make JS and CSS external Reduce DNS lookups Minify JS Avoid redirects Remove duplicate scripts Turn off ETags Make AJAX cacheable and small
  • 50. Rule 1: Make fewer HTTP requests image maps CSS sprites inline images combined scripts, combined stylesheets
  • 51. Image maps server-side <a href="navbar.cgi"><img ismap src="imagemap.gif"></a> -> http://.../navbar.cgi?127,13 client-side – preferred <img usemap="#map1" border=0 src="/images/imagemap.gif"> <map name="map1"> <area shape="rect" coords="0,0,31,31" href="home.html" title="Home"> … </map> drawbacks: must be contiguous defining area coordinates – tedious, errors http://www.w3.org/TR/html401/struct/objects.html#h-13.6
  • 52. CSS Sprites – Preferred <span style=" background-image: url('sprites.gif'); background-position: -260px -90px;"> </span> size of combined image is less not supported in Opera 6 http://alistapart.com/articles/sprites
  • 53. Inline Images data: URL scheme data:[<mediatype>][;base64],<data> <IMG ALT=”Red Star” SRC="data:image/gif;base64,R0lGODlhDAAMALMLAPN8ffBiYvWWlvrKy/FvcPewsO9VVfajo+w6O/zl5estLv/8/AAAAAAAAAAAAAAAACH5BAEAAAsALAAAAAAMAAwAAAQzcElZyryTEHyTUgknHd9xGV+qKsYirKkwDYiKDBiatt2H1KBLQRFIJAIKywRgmhwAIlEEADs="> not supported in IE avoid increasing size of HTML pages: put inline images in cached stylesheets http://tools.ietf.org/html/rfc2397
  • 55. Combined Scripts,Combined Stylesheets combining six scripts into one eliminates five HTTP requests challenges: develop as separate modules number of possible combinations vs. loading more than needed maximize browser cache one solution: dynamically combine and cache
  • 56. Rule 2: Use a CDN distribute your static content before distributing your dynamic content
  • 57. Rule 3: Add an Expires header not just for images
  • 58. Rule 4: Gzip components you can affect users' download times 90%+ of browsers support compression
  • 59. Gzip compresses more Gzip supported in more browsers Gzip vs. Deflate
  • 60. Gzip: not just for HTML gzip scripts, stylesheets, XML, JSON (not images, PDF)
  • 61. Gzip Configuration Apache 2.x: mod_deflate AddOutputFilterByType DEFLATE text/html text/css application/x-javascript HTTP request Accept-Encoding: gzip, deflate HTTP response Content-Encoding: gzip Vary: Accept-Encoding needed for proxies
  • 62. Gzip Edge Cases <1% of browsers have problems with gzip IE 5.5: http://support.microsoft.com/default.aspx?scid=kb;en-us;Q313712 IE 6.0: http://support.microsoft.com/default.aspx?scid=kb;en-us;Q31249 Netscape 3.x, 4.x http://www.schroepl.net/projekte/mod_gzip/browser.htm consider adding Cache-Control: Private remove ETags (Rule 13) hard to diagnose; problem getting smaller
  • 63. Rule 5: Put CSS at the top stylesheets block rendering in IE http://stevesouders.com/examples/css-bottom.php solution: put stylesheets in HEAD (per spec) avoids Flash of Unstyled Content use LINK (not @import)
  • 65. Rule 6: Move scripts to the bottom scripts block parallel downloads across all hostnames scripts block rendering of everything below them in the page IE and FF http://stevesouders.com/examples/js-middle.php
  • 66. Rule 6: Move scripts to the bottom script defer attribute is not a solution blocks rendering and downloads in FF slight blocking in IE solution: move them as low in the page as possible
  • 67. Rule 7: Avoid CSS expressions used to set CSS properties dynamically in IE width: expression( document.body.clientWidth < 600 ? “600px” : “auto” ); problem: expressions execute many times mouse move, key press, resize, scroll, etc. http://stevesouders.com/examples/expression-counter.php
  • 68. One-Time Expressions expression overwrites itself <style> P { background-color: expression(altBgcolor(this)); } </style> <script> function altBgcolor(elem) { elem.style.backgroundColor = (new Date()).getHours()%2 ? "#F08A00" : "#B8D4FF"; } </script>
  • 69. Event Handlers tie behavior to (fewer) specific events window.onresize = setMinWidth; function setMinWidth() { varaElements = document.getElementsByTagName("p"); for ( vari = 0; i < aElements.length; i++ ) { aElements[i].runtimeStyle.width = ( document.body.clientWidth<600 ? "600px" : "auto" ); } }
  • 70. Rule 8: Make JS and CSS external inline: HTML document is bigger external: more HTTP requests, but cached variables page views per user (per session) empty vs. full cache stats component re-use external is typically better home pages may be an exception
  • 71. Post-Onload Download inline in front page download external files after onload window.onload = downloadComponents; function downloadComponents() { var elem = document.createElement("script"); elem.src = "http://.../file1.js"; document.body.appendChild(elem); ... } speeds up secondary pages
  • 72. Dynamic Inlining start with post-onload download set cookie after components downloaded server-side: if cookie, use external else, do inline with post-onload download cookie expiration date is key speeds up all pages
  • 73. Rule 9: Reduce DNS lookups typically 20-120 ms block parallel downloads OS and browser both have DNS caches
  • 74. TTL (Time To Live) TTL – how long record can be cached browser settings override TTL
  • 75. Browser DNS Cache IE DnsCacheTimeout: 30 minutes KeepAliveTimeout: 1 minute ServerInfoTimeout: 2 minutes Firefox network.dnsCacheExpiration: 1 minute network.dnsCacheEntries: 20 network.http.keep-alive.timeout: 5 minutes Fasterfox: 1 hour, 512 entries, 30 seconds
  • 76. Reducing DNS Lookups fewer hostnames – 2-4 keep-alive
  • 77. Rule 10: Minify JavaScript minify inline scripts, too
  • 78. Minify vs. Obfuscate minify – it's safer http://crockford.com/javascript/jsmin http://dojotoolkit.org/docs/shrinksafe
  • 79. Rule 11: Avoid redirects 3xx status codes – mostly 301 and 302 HTTP/1.1 301 Moved Permanently Location: http://stevesouders.com/newuri add Expires headers to cache redirects worst form of blocking http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
  • 81. Avoid Redirects missing trailing slash http://astrology.yahoo.com/astrology use Alias or DirectorySlash mod_rewrite CNAMEs log referer – track internal links outbound links – harder beacons – beware of race condition XHR – bail at readyState 2
  • 82. Rule 12: Remove duplicate scripts hurts performance extra HTTP requests (IE only) extra executions atypical? 2 of 10 top sites contain duplicate scripts team size, # of scripts
  • 83. Script Insertion Functions <?php function insertScript($jsfile) { if ( alreadyInserted($jsfile) ) { return; } pushInserted($jsfile); if ( hasDependencies($jsfile) ) { $dependencies = getDependencies($jsfile); for ( $i = 0; $i < count($dependencies); $i++ ) { insertScript($dependencies[$i]); } } echo '<script type="text/javascript" src="' . getVersion($jsfile) . '"></script>"; } ?>
  • 84. Rule 13: Turn off ETags unique identifier returned in response ETag: "c8897e-aee-4165acf0" Last-Modified: Thu, 07 Oct 2004 20:54:08 GMT used in conditional GET requests If-None-Match: "c8897e-aee-4165acf0" If-Modified-Since: Thu, 07 Oct 2004 20:54:08 GMT if ETag doesn't match, can't send 304
  • 85. The Problem with ETags ETag for a single entity is always different across servers ETag format Apache: inode-size-timestamp IIS: Filetimestamp:ChangeNumber Sites with >1 server return too few 304s (n-1)/n Remove them Apache: FileETag none IIS: http://support.microsoft.com/kb/922703/
  • 86. Rule 14: Make AJAX cacheable and small XHR, JSON, iframe, dynamic scripts can still be cached, minified, and gzipped a personalized response should still be cacheable by that person
  • 87. AJAX Example: Yahoo! Mail Beta address book XML request -> GET /yab/[...]&r=0.5289571053069156 HTTP/1.1 Host: us.xxx.mail.yahoo.com ← HTTP/1.1 200 OK Date: Thu, 12 Apr 2007 19:39:09 GMT Cache-Control: private,max-age=0 Last-Modified: Sat, 31 Mar 2007 01:17:17 GMT Content-Type: text/xml; charset=utf-8 Content-Encoding: gzip address book changes infrequently cache it; add last-modified-time in URL
  • 89. IBM Page Detailer packet sniffer Windows only IE, FF, any .exe c:indowsd_WS2s.ini Executable=(NETSCAPE.EXE),(NETSCP6.EXE),(firefox.exe) free trial, $300 license http://alphaworks.ibm.com/tech/pagedetailer
  • 91. Fasterfox measures load time of pages alters config settings for faster loading Firefox extension free http://fasterfox.mozdev.org/
  • 92. LiveHTTPHeaders view HTTP headers Firefox extension free http://livehttpheaders.mozdev.org/
  • 93. Firebug web development evolved inspect and edit HTML tweak and visualize CSS debug and profile JavaScript monitor network activity (caveat) Firefox extension free http://getfirebug.com/
  • 95. YSlow performance lint tool grades web pages for each rule Firefox extension Yahoo! internal tool
  • 96.
  • 98. Takeaways focus on the front-end harvest the low-hanging fruit you do control user response times LOFNO – be an advocate for your users
  • 99. Links book: http://www.oreilly.com/catalog/9780596514211/ examples: http://stevesouders.com/examples/ image maps: http://www.w3.org/TR/html401/struct/objects.html#h-13.6 CSS sprites: http://alistapart.com/articles/sprites inline images: http://tools.ietf.org/html/rfc2397 jsmin: http://crockford.com/javascript/jsmin dojo compressor: http://dojotoolkit.org/docs/shrinksafe HTTP status codes: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html IBM Page Detailer: http://alphaworks.ibm.com/tech/pagedetailer Fasterfox: http://fasterfox.mozdev.org/ LiveHTTPHeaders: http://livehttpheaders.mozdev.org/ Firebug: http://getfirebug.com/ YUIBlog: http://yuiblog.com/blog/2006/11/28/performance-research-part-1/ http://yuiblog.com/blog/2007/01/04/performance-research-part-2/ http://yuiblog.com/blog/2007/03/01/performance-research-part-3/ http://yuiblog.com/blog/2007/04/11/performance-research-part-4/ YDN: http://developer.yahoo.net/blog/archives/2007/03/high_performanc.html http://developer.yahoo.net/blog/archives/2007/04/rule_1_make_few.html