Presentation is loading. Please wait.

Presentation is loading. Please wait.

High Performance Web Sites 14 rules for faster pages Steve Souders Tenni Theurer

Similar presentations


Presentation on theme: "High Performance Web Sites 14 rules for faster pages Steve Souders Tenni Theurer"— Presentation transcript:

1 High Performance Web Sites 14 rules for faster pages Steve Souders Tenni Theurer http://developer.yahoo.com/performance/

2 Exceptional Performance quantify and improve the performance of all Yahoo! products worldwide center of expertise build tools, analyze data gather, research, and evangelize best practices

3 Scope performance breaks into two categories –response time –efficiency current focus is response time of web products

4 The Importance of Frontend Performance Backend = 5% Frontend = 95% Even primed cache, frontend = 88%

5 Time Spent on the Frontend Empty CachePrimed Cache amazon.com82%86% aol.com94%86% cnn.com81%92% ebay.com98%92% google.com86%64% msn.com97%95% myspace.com96%86% wikipedia.org80%88% yahoo.com95%88% youtube.com97%95%

6 The Performance Golden Rule 80-90% of the end-user response time is spent on the frontend. Start there. Greater potential for improvement Simpler Proven to work

7 Agenda Performance Research 14 Rules Case Studies Evangelism Live Analysis

8 Performance Research

9 perceived response time what is the end users experience? slow crawl boring snail stagnant unexceptional yawn unresponsive impatient delay moderate blah subdue drag apathetic prolong slack load sluggish sleepy late unexciting reduced lag complex heavy unmemorable obscure why wait performance speed enjoyable urgent instant accelerate perception snap achievement better improve action pleasant pace quick promote swift cool maximum drive prompt advance fast hurry rush satisfying feel exceptional brisk rapid exciting

10 User Perception Usability and perception are important for performance. The users 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.

11 http://yuiblog.com/blog/2006/11/28/performance-research-part-1/

12 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.

13 Empty vs. Primed Cache user requests www.yahoo.com with an empty cache

14 Empty vs. Primed Cache user re-requests www.yahoo.com with a primed cache Expires header

15 Empty vs. Primed Cache empty cache 2.4 seconds primed cache 0.9 seconds 83% fewer bytes 90% fewer HTTP requests

16 How much does this benefit our users? It depends on how many users have components in cache. What percentage of users view a page with an empty cache * ? * Empty cache means the browser has to request the components instead of pulling them from the browser disk cache. What percentage of page views are done with an empty cache * ?

17 http://yuiblog.com/blog/2007/01/04/performance-research-part-2/

18 Add a new image to your page with the following response headers: Expires: Thu, 15 Apr 2004 20:00:00 GMT Last-Modified: Wed, 28 Sep 2006 23:49:57 GMT } 1 px Browser Cache Experiment

19 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.

20 Browser Cache Experiment What percentage of users view with an empty cache? # unique users with at least one 200 response total # unique users What percentage of page views are done with an empty cache? total # of 200 responses # of 200 + # of 304 responses } 1 px

21 Surprising Results page views with empty cache 40-60% ~20% users with empty cache

22 Experiment Takeaways The empty cache user experience is more prevalent than you think! Optimize for both primed cache and empty cache experience.

23 http://yuiblog.com/blog/2007/03/01/performance-research-part-3

24 Impact of Cookies on Response Time 80 ms delay dialup users Cookie SizeTimeDelta 0 bytes78 ms0 ms 500 bytes79 ms+1 ms 1000 bytes94 ms+16 ms 1500 bytes109 ms+31 ms 2000 bytes125 ms+47 ms 2500 bytes141 ms+63 ms 3000 bytes156 ms+78 ms keep sizes low

25 .yahoo.com cookie sizes

26 Analysis of Cookie Sizes across the Web Total Cookie Size Amazon60 bytes Google72 bytes Yahoo122 bytes CNN184 bytes YouTube218 bytes MSN268 bytes eBay331 bytes MySpace500 bytes

27 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

28 http://yuiblog.com/blog/2007/04/11/performance-research-part-4/

29 Parallel Downloads Two componentsin parallelper hostname GIF HTTP/1.1

30 Two in parallel Four in parallel Eight in parallel Parallel Downloads

31 Maximizing Parallel Downloads response time (seconds) aliases

32 Maximizing Parallel Downloads response time (seconds) aliases

33 Maximizing Parallel Downloads response time (seconds) aliases

34 Maximizing Parallel Downloads response time (seconds) rule of thumb: use at least two but no more than four aliases

35 Experiment Takeaways consider the effects of CPU thrashing DNS lookup times vary across ISPs and geographic locations domain names may not be cached

36 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/

37 14 Rules

38 1.Make fewer HTTP requests 2.Use a CDN 3.Add an Expires header 4.Gzip components 5.Put stylesheets at the top 6.Move scripts to the bottom 7.Avoid CSS expressions 8.Make JS and CSS external 9.Reduce DNS lookups 10.Minify JS 11.Avoid redirects 12.Remove duplicate scripts 13.Configure ETags 14.Make AJAX cacheable

39 Rule 1: Make fewer HTTP requests CSS sprites combined scripts, combined stylesheets image maps inline images

40 CSS Sprites size of combined image is less http://alistapart.com/articles/sprites

41 Combined Scripts, Combined Stylesheets ScriptsStylesheets amazon.com31 aol.com181 cnn.com112 ebay.com72 froogle.google.com11 msn.com91 myspace.com22 wikipedia.org31 yahoo.com41 youtube.com73 Average6.51.5

42 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

43 Image maps server-side http://.../navbar.cgi?127,13 client-side – preferred … drawbacks: –must be contiguous –defining area coordinates – tedious, errors http://www.w3.org/TR/html401/struct/objects.html#h-13.6

44 Inline Images data: URL scheme data:[ ][;base64], Red not supported in IE avoid increasing size of HTML pages: put inline images in cached stylesheets http://tools.ietf.org/html/rfc2397

45 Rule 2: Use a CDN distribute your static content before distributing your dynamic content amazon.comAkamai aol.comAkamai cnn.com ebay.comAkamai, Mirror Image google.com msn.comSAVVIS myspace.comAkamai, Limelight wikipedia.org yahoo.comAkamai youtube.com

46 Rule 3: Add an Expires header not just for images ImagesStylesheetsScripts % with Expires Median Age amazon.com0/620/10/30%114 days aol.com23/431/16/1848%217 days cnn.com0/1380/22/111%227 days ebay.com16/200/20/755%140 days froogle.google.com1/230/1 4%454 days msn.com32/351/13/980%34 days myspace.com0/180/2 0%1 day wikipedia.org6/81/12/375%1 day yahoo.com23/231/14/4100%n/a youtube.com0/320/30/70%26 days

47 Rule 4: Gzip components you can affect users' download times 90%+ of browsers support compression

48 Gzip: not just for HTML HTMLScriptsStylesheets amazon.comx aol.comxsome cnn.com ebay.comx froogle.google.comxxx msn.comxdeflate myspace.comxxx wikipedia.orgxxx yahoo.comxxx youtube.comxsome gzip scripts, stylesheets, XML, JSON (not images, PDF)

49 Gzip compresses more Gzip supported in more browsers Gzip vs. Deflate GzipDeflate Size SavingsSizeSavings Script3.3K1.1K67%1.1K66% Script39.7K14.5K64%16.6K58% Stylesheet1.0K0.4K56%0.5K52% Stylesheet14.1K3.7K73%4.7K67%

50 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

51 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

52 Rule 5: Put stylesheets at the top stylesheets block rendering in IE solution: put stylesheets in HEAD (per spec) avoids Flash of Unstyled Content use LINK (not @import)

53 Slowest is Fastest CSS at the bottom: resources load faster, but nothing renders CSS at the top: resources take longer, but render progressively @import at the top: same problems as bottom right choice

54 Rule 6: Move scripts to the bottom scripts block parallel downloads across all hostnames scripts block rendering of everything below them in the page script defer attribute is not a solution –blocks rendering and downloads in FF –slight blocking in IE

55 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. alternatives: –one-time expressions –event handlers

56 One-Time Expressions expression overwrites itself P { background-color: expression(altBgcolor(this)); } function altBgcolor(elem) { elem.style.backgroundColor = (new Date()).getHours()%2 ? "#F08A00" : "#B8D4FF"; }

57 Event Handlers tie behavior to (fewer) specific events window.onresize = setMinWidth; function setMinWidth() { var aElements = document.getElementsByTagName("p"); for ( var i = 0; i < aElements.length; i++ ) { aElements[i].runtimeStyle.width = ( document.body.clientWidth<600 ? "600px" : "auto" ); } }

58 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. primed cache stats –component re-use external is typically better extra credit: post-onload download, dynamic inlining

59 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

60 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

61 Rule 9: Reduce DNS lookups typically 20-120 ms block parallel downloads OS and browser both have DNS caches

62 TTL (Time To Live) www.amazon.com1 minute www.aol.com1 minute www.cnn.com10 minutes www.ebay.com1 hour www.google.com5 minutes www.msn.com5 minutes www.myspace.com1 hour www.wikipedia.org1 hour www.yahoo.com1 minute www.youtube.com5 minutes TTL – how long record can be cached browser settings override TTL

63 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

64 Reducing DNS Lookups fewer hostnames – 2-4 keep-alive

65 minify inline scripts, too Rule 10: Minify JavaScript Minify External? Minify Inline? www.amazon.comno www.aol.comno www.cnn.comno www.ebay.comyesno froogle.google.comyes www.msn.comyes www.myspace.comno www.wikipedia.orgno www.yahoo.comyes www.youtube.comno

66 Minify vs. Obfuscate OriginalJSMin SavingsDojo Savings www.amazon.com204K31K (15%)48K (24%) www.aol.com44K4K (10%) www.cnn.com98K19K (20%)24K (25%) www.myspace.com88K23K (27%)24K (28%) www.wikipedia.org42K14K (34%)16K (38%) www.youtube.com34K8K (22%)10K (29%) Average85K17K (21%)21K (25%) minify – it's safer http://crockford.com/javascript/jsmin http://dojotoolkit.org/docs/shrinksafe not much difference

67 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

68 Redirects www.amazon.comno www.aol.comyes – secondary page www.cnn.comyes – initial page www.ebay.comyes – secondary page froogle.google.comno www.msn.comyes – initial page www.myspace.comyes – secondary page www.wikipedia.orgyes – secondary page www.yahoo.comyes – secondary page www.youtube.comno

69 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

70 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

71 Script Insertion Functions "; } ?>

72 Rule 13: Configure 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 ETag format –Apache: inode-size-timestamp –IIS: Filetimestamp:ChangeNumber Use 'em or lose 'em –Apache: FileETag none –IIS: http://support.microsoft.com/kb/922703/

73 Rule 14: Make AJAX cacheable XHR, JSON, iframe, dynamic scripts can still be cached (and minified, and gzipped) a personalized response should still be cacheable for that person

74 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

75 Case Studies

76 Case Study: move JS to onload remove bottom tabs avoid redirects image sprites host JS on CDN combine JS files

77 Case Study: move JS to onload remove bottom tabs avoid redirects images sprites host JS on CDN combine JS files 40-50%

78 Evangelism

79 Book High Performance Web Sites Conferences Yahoo! F2E Summit Web 2.0 Expo Rich Web Experience Blogs YUI Blog: http://yuiblog.com/blog/category/performance YDN Blog: http://developer.yahoo.com/performance/ Open Source YSlow OSCon Ajax Experience Blogher Future of Web Apps

80 YSlow http://developer.yahoo.com/yslow performance lint tool grades web pages for each rule Firefox add-on integrated with Firebug open source license

81

82 Ten Top U.S Web Sites Page Weight Response Time YSlow Grade www.amazon.com405K15.9 secD www.aol.com182K11.5 secF www.cnn.com502K22.4 secF www.ebay.com275K9.6 secC froogle.google.com18K1.7 secA www.msn.com221K9.3 secF www.myspace.com205K7.8 secD www.wikipedia.org106K6.2 secC www.yahoo.com178K5.9 secA www.youtube.com139K9.6 secD

83 Strong Correlation total page weight response time inverse YSlow grade correlation(resp time, page weight) = 0.94 correlation(resp time, inverse YSlow) = 0.76

84 Live Analysis

85 IBM Page Detailer packet sniffer Windows only IE, FF, any.exe c:\windows\wd_WS2s.ini Executable=(NETSCAPE.EXE),(NETSCP6.EXE),(firefox.exe) free trial, $300 license http://alphaworks.ibm.com/tech/pagedetailer

86

87 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/

88 Takeaways focus on the frontend harvest the low-hanging fruit you do control user response times small investment up front keeps on giving LOFNO – be an advocate for your users

89 Steve Souders souders@yahoo-inc.com Tenni Theurer tenni@yahoo-inc.com

90 CC Images Used "Need for Speed" by Amnemon: http://www.flickr.com/photos/marinacvinhal/379111290/ "Max speed 15kmh" by xxxtoff: http://www.flickr.com/photos/xxxtoff/219781763/ "maybe" by Tal Bright: http://www.flickr.com/photos/bright/118197469/ "takeout" by dotpolka: http://www.flickr.com/photos/dotpolka/249129144/ "how do they do that" by Fort Photo: http://www.flickr.com/photos/fortphoto/388825145/ "Absolutely Nothing is Allowed Here" by Vicki & Chuck Rogers: http://www.flickr.com/photos/two-wrongs/205467442/ "Zipper Pocket" by jogales: http://www.flickr.com/photos/jogales/11519576/ "new briefcase" by dcJohn: http://www.flickr.com/photos/dcjohn/85504455/ "Told you it was me!" by Pug!: http://flickr.com/photos/pugspace/1277023154/ "Robert's Legion" by dancharvey: http://www.flickr.com/photos/dancharvey/2647529/ "thank you" by nj dodge: http://flickr.com/photos/nj_dodge/187190601/


Download ppt "High Performance Web Sites 14 rules for faster pages Steve Souders Tenni Theurer"

Similar presentations


Ads by Google