SlideShare a Scribd company logo
High Performance Web Sites14 rules for faster-loading pagesParham FazelHooman NorooziniaTosan Tech Talk2011/06
Introduction
Exceptional Performancestarted in 2004quantify and improve the performance of all Yahoo! products worldwidecenter of expertisebuild tools, analyze datagather, research, and evangelize best practices
Scopeperformance breaks into two categoriesresponse timeefficiencycurrent focus is response timeof web products
Rough Cuts: nowHardcopy: Summer 2007http://www.oreilly.com/catalog/9780596514211/
Steve Soudersemployer:GoogleHead Performance Engineerblog: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-endBack-end vs. Front-end
The Performance Golden Rule80-90% of the end-user response time is spent on the front-end. Start there.Greater potential for improvement
Simpler
Proven to workSchedulePerformance Researchbreak14 RulesbreakCase StudiesLive Analysis
Performance Research
perceived response timeslowcrawlboringsnailstagnantunexceptionalyawnunresponsiveimpatientdelaymoderateblahsubduedragapatheticprolongslackloadsluggishsleepylateunexcitingreducedlagcomplex heavyunmemorableobscurewhy waitperformance speed enjoyable urgentinstantaccelerateperceptionsnapachievement betterimproveaction pleasantpacequickpromoteswiftcoolmaximumdriveprompt advance fast hurryrushsatisfyingfeelexceptionalbriskrapid excitingwhat is the end user’s experience?
User PerceptionUsability 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 RuleVilfredo Pareto: 80% of consequences come from 20% of causesFocus on the 20% that affects 80% of the end-user response time.Start at the front-end.
231user re-requests www.yahoo.comuser requests www.yahoo.comuser requests other web pagesEmpty vs. Full Cache
231user re-requests www.yahoo.comuser requests www.yahoo.comuser requests other web pagesEmpty vs. Full Cachewith an empty cache
231user re-requests www.yahoo.comuser requests www.yahoo.comuser requests other web pagesEmpty vs. Full Cache
Empty vs. Full Cache21user requests www.yahoo.comuser requests other web pages3user re-requests www.yahoo.comExpires headerwith a full cache
Empty vs. Full Cache						   empty cache							2.4 seconds						   full cache							0.9 seconds83% fewer bytes90% fewer HTTP requests
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 componentsinstead of pulling them from the browser disk cache.What percentage of page viewsare done with an empty cache*?http://yuiblog.com/blog/2007/01/04/performance-research-part-2/
}1 pxAdd 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 GMTLast-Modified: Wed, 28 Sep 2006 23:49:57 GMTBrowser Cache Experiment
Browser Cache ExperimentRequests 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 Resultsusers withempty cachepage views withempty cache40-60% ~20%
Experiment TakeawaysKeep 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
1user requests www.yahoo.comHTTP Quick ReviewHTTP response header sent by the web server:HTTP/1.1 200 OKContent-Type: text/html; charset=utf-8Set-Cookie: C=abcdefghijklmnopqrstuvwxyz; domain=.yahoo.com
1user requests www.yahoo.comHTTP Quick Review2user requests finance.yahoo.comHTTP request header sent by the browser:GET / HTTP/1.1Host: finance.yahoo.comUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; …Cookie: C=abcdefghijklmnopqrstuvwxyz;
31user requests autos.yahoo.comuser requests www.yahoo.comHTTP Quick ReviewHTTP request header sent by the browser:GET / HTTP/1.1Host: autos.yahoo.comUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; …Cookie: C=abcdefghijklmnopqrstuvwxyz;
41user requests mail.yahoo.comuser requests www.yahoo.comHTTP Quick ReviewHTTP request header sent by the browser:GET / HTTP/1.1Host: mail.yahoo.comUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; …Cookie: C=abcdefghijklmnopqrstuvwxyz;
51user requests tech.yahoo.comuser requests www.yahoo.comHTTP Quick ReviewHTTP request header sent by the browser:GET / HTTP/1.1Host: tech.yahoo.comUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; …Cookie: C=abcdefghijklmnopqrstuvwxyz;
Impact of Cookies on Response Timedialup users80 ms delaykeep sizes low
.yahoo.com cookie sizes
Analysis of Cookie Sizes across the Web
Experiment Takeawayseliminate unnecessary cookieskeep cookie sizes lowset cookies at appropriate domain levelset Expires date appropriatelyearlier date or none removes cookie sooner
http://yuiblog.com/blog/2007/04/11/performance-research-part-4/
Parallel DownloadsGIFGIFGIFGIFGIFGIFTwo componentsin parallelper hostnameHTTP/1.1
Parallel DownloadsTwo in parallelFour in parallelEight in parallel
Maximizing Parallel Downloadsresponse time (seconds)aliases
Maximizing Parallel Downloadsresponse time (seconds)aliases
Maximizing Parallel Downloadsresponse time (seconds)aliases
Maximizing Parallel Downloadsresponse time (seconds)rule of thumb: use at least two but no more than four aliases
Experiment Takeawaysconsider the effects of CPU thrashingDNS lookup times vary across ISPs and geographic locationsdomain names may not be cached
SummaryWhat the 80/20 Rule Tells Us about Reducing HTTP Requestshttp://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 Crumbleshttp://yuiblog.com/blog/2007/01/04/performance-research-part-2/Maximizing Parallel Downloads in the Carpool Lanehttp://yuiblog.com/blog/2007/04/11/performance-research-part-4/
14 Rules
14 RulesMake fewer HTTP requestsUse a CDNAdd an Expires headerGzip componentsPut CSS at the topMove JS to the bottomAvoid CSS expressionsMake JS and CSS externalReduce DNS lookupsMinify JSAvoid redirectsRemove duplicate scriptsTurn off ETagsMake AJAX cacheable and small
Rule 1: Make fewer HTTP requestsimage mapsCSS spritesinline imagescombined scripts, combined stylesheets
Image mapsserver-side<a href="navbar.cgi"><img ismap src="imagemap.gif"></a>-> http://.../navbar.cgi?127,13client-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 contiguousdefining area coordinates – tedious, errorshttp://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 lessnot supported in Opera 6http://alistapart.com/articles/sprites
Inline Imagesdata: URL schemedata:[<mediatype>][;base64],<data><IMG ALT=”Red Star”SRC="data:image/gif;base64,R0lGODlhDAAMALMLAPN8ffBiYvWWlvrKy/FvcPewsO9VVfajo+w6O/zl5estLv/8/AAAAAAAAAAAAAAAACH5BAEAAAsALAAAAAAMAAwAAAQzcElZyryTEHyTUgknHd9xGV+qKsYirKkwDYiKDBiatt2H1KBLQRFIJAIKywRgmhwAIlEEADs=">not supported in IEavoid increasing size of HTML pages:put inline images in cached stylesheetshttp://tools.ietf.org/html/rfc2397
Combined Scripts, Combined Stylesheets
Combined Scripts,Combined Stylesheetscombining six scripts into one eliminates five HTTP requestschallenges: develop as separate modulesnumber of possible combinations vs. loading more than neededmaximize browser cacheone solution:dynamically combine and cache
Rule 2: Use a CDNdistribute 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 times90%+ of browsers support compression
Gzip compresses moreGzip supported in more browsersGzip vs. Deflate
Gzip: not just for HTMLgzip scripts, stylesheets, XML, JSON (not images, PDF)
Gzip Configuration Apache 2.x: mod_deflateAddOutputFilterByType DEFLATE text/html text/css application/x-javascriptHTTP requestAccept-Encoding: gzip, deflateHTTP responseContent-Encoding: gzipVary: Accept-Encodingneeded for proxies
Gzip Edge Cases <1% of browsers have problems with gzipIE 5.5:     http://support.microsoft.com/default.aspx?scid=kb;en-us;Q313712IE 6.0:    http://support.microsoft.com/default.aspx?scid=kb;en-us;Q31249Netscape 3.x, 4.x    http://www.schroepl.net/projekte/mod_gzip/browser.htmconsider adding Cache-Control: Privateremove ETags (Rule 13)hard to diagnose; problem getting smaller
Rule 5: Put CSS at the top stylesheets block rendering in IEhttp://stevesouders.com/examples/css-bottom.phpsolution: put stylesheets in HEAD (per spec)avoids Flash of Unstyled Contentuse LINK (not @import)
Slowest is Fastest
Rule 6: Move scripts to the bottom scripts block parallel downloads across all hostnamesscripts block rendering of everything below them in the pageIE and FFhttp://stevesouders.com/examples/js-middle.php
Rule 6: Move scripts to the bottom script defer attribute is not a solutionblocks rendering and downloads in FFslight blocking in IEsolution: move them as low in the page as possible
Rule 7: Avoid CSS expressions used to set CSS properties dynamically in IEwidth: expression(   document.body.clientWidth < 600 ?   “600px” : “auto” );problem: expressions execute many timesmouse move, key press, resize, scroll, etc.http://stevesouders.com/examples/expression-counter.php
One-Time Expressionsexpression 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 Handlerstie behavior to (fewer) specific eventswindow.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 biggerexternal: more HTTP requests, but cachedvariablespage views per user (per session)empty vs. full cache statscomponent re-useexternal is typically betterhome pages may be an exception
Post-Onload Downloadinline in front pagedownload external files after onloadwindow.onload = downloadComponents;function downloadComponents() {    var elem = document.createElement("script");    elem.src = "http://.../file1.js";    document.body.appendChild(elem);    ...}speeds up secondary pages
Dynamic Inliningstart with post-onload downloadset cookie after components downloadedserver-side: if cookie, use externalelse, do inline with post-onload downloadcookie expiration date is keyspeeds up all pages
Rule 9: Reduce DNS lookups typically 20-120 msblock parallel downloadsOS and browser both have DNS caches
TTL (Time To Live)TTL – how long record can be cachedbrowser settings override TTL
Browser DNS CacheIEDnsCacheTimeout: 30 minutesKeepAliveTimeout: 1 minuteServerInfoTimeout: 2 minutesFirefoxnetwork.dnsCacheExpiration: 1 minutenetwork.dnsCacheEntries: 20network.http.keep-alive.timeout: 5 minutesFasterfox: 1 hour, 512 entries, 30 seconds
Reducing DNS Lookupsfewer hostnames – 2-4keep-alive
Rule 10: Minify JavaScriptminify inline scripts, too
Minify vs. Obfuscateminify – it's saferhttp://crockford.com/javascript/jsminhttp://dojotoolkit.org/docs/shrinksafe
Rule 11: Avoid redirects3xx status codes – mostly 301 and 302HTTP/1.1 301 Moved PermanentlyLocation: http://stevesouders.com/newuriadd Expires headers to cache redirectsworst form of blockinghttp://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
Redirects
Avoid Redirectsmissing trailing slashhttp://astrology.yahoo.com/astrologyuse Alias or DirectorySlashmod_rewriteCNAMEslog referer – track internal linksoutbound links – harderbeacons – beware of race conditionXHR – bail at readyState 2
Rule 12: Remove duplicate scriptshurts performanceextra HTTP requests (IE only)extra executionsatypical?2 of 10 top sites contain duplicate scriptsteam size, # of scripts
Script Insertion Functions<?phpfunction 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 ETagsunique identifier returned in responseETag: "c8897e-aee-4165acf0"Last-Modified: Thu, 07 Oct 2004 20:54:08 GMTused in conditional GET requestsIf-None-Match: "c8897e-aee-4165acf0"If-Modified-Since: Thu, 07 Oct 2004 20:54:08 GMTif ETag doesn't match, can't send 304
The Problem with ETagsETag for a single entity is always different across serversETag formatApache: inode-size-timestampIIS: Filetimestamp:ChangeNumberSites with >1 server return too few 304s(n-1)/nRemove themApache: FileETag noneIIS: http://support.microsoft.com/kb/922703/
Rule 14: Make AJAX cacheable and smallXHR, JSON, iframe, dynamic scripts can still be cached, minified, and gzippeda personalized response should still be cacheable by that person
AJAX Example: Yahoo! Mail Betaaddress 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: gzipaddress book changes infrequentlycache it; add last-modified-time in URL
Live Analysis
IBM Page Detailerpacket snifferWindows onlyIE, FF, any .exec:\windows\wd_WS2s.iniExecutable=(NETSCAPE.EXE),(NETSCP6.EXE),(firefox.exe)free trial, $300 licensehttp://alphaworks.ibm.com/tech/pagedetailer
http://alphaworks.ibm.com/tech/pagedetailer
Fasterfoxmeasures load time of pagesalters config settings for faster loadingFirefox extensionfreehttp://fasterfox.mozdev.org/
LiveHTTPHeadersview HTTP headersFirefox extensionfreehttp://livehttpheaders.mozdev.org/
Firebugweb development evolvedinspect and edit HTMLtweak and visualize CSSdebug and profile JavaScriptmonitor network activity (caveat)Firefox extensionfreehttp://getfirebug.com/
http://getfirebug.com/
YSlowperformance lint toolgrades web pages for each ruleFirefox extensionYahoo! internal tool
High Performance Websites
Conclusion
Takeawaysfocus on the front-endharvest the low-hanging fruityou do control user response timesLOFNO – be an advocate for your users
Linksbook: http://www.oreilly.com/catalog/9780596514211/examples: http://stevesouders.com/examples/image maps: http://www.w3.org/TR/html401/struct/objects.html#h-13.6CSS sprites: http://alistapart.com/articles/spritesinline images: http://tools.ietf.org/html/rfc2397jsmin: http://crockford.com/javascript/jsmindojo compressor: http://dojotoolkit.org/docs/shrinksafeHTTP status codes: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.htmlIBM Page Detailer: http://alphaworks.ibm.com/tech/pagedetailerFasterfox: 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.htmlhttp://developer.yahoo.net/blog/archives/2007/04/rule_1_make_few.html

More Related Content

PPT
High Performance Websites By Souders Steve
PPT
High Performance Web Sites
PPT
Plop
PPT
腾讯大讲堂09 如何建设高性能网站
PDF
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...
PDF
Optimizing web performance (Fronteers edition)
PPTX
SearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital Marketers
PDF
Performance Of Web Applications On Client Machines
High Performance Websites By Souders Steve
High Performance Web Sites
Plop
腾讯大讲堂09 如何建设高性能网站
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...
Optimizing web performance (Fronteers edition)
SearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital Marketers
Performance Of Web Applications On Client Machines

What's hot (20)

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

Similar to High Performance Websites (20)

PPT
腾讯大讲堂09 如何建设高性能网站
PPT
腾讯大讲堂09 如何建设高性能网站
PPT
Os Souders
PPT
腾讯大讲堂09 如何建设高性能网站
PDF
腾讯大讲堂09 如何建设高性能网站
PPT
Csdn Drdobbs Tenni Theurer Yahoo
PDF
Performance tuning of Websites
PDF
14 Tips For Faster Web Apps
PDF
Web performance mercadolibre - ECI 2013
PPT
High Performance Web Pages - 20 new best practices
PDF
Go Faster, Webmaster
PDF
Go Faster, Webmasters
PDF
7 Habits of Exceptional Performance
PDF
High Performance Ajax Applications
PDF
Web performance optimization - MercadoLibre
PPTX
Analysis of Google Page Speed Insight
PPTX
The Need for Speed - SMX Sydney 2013
PPTX
10 things you can do to speed up your web app today stir trek edition
PDF
High performance website
PPTX
Art and Science of Web Sites Performance: A Front-end Approach
腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站
Os Souders
腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站
Csdn Drdobbs Tenni Theurer Yahoo
Performance tuning of Websites
14 Tips For Faster Web Apps
Web performance mercadolibre - ECI 2013
High Performance Web Pages - 20 new best practices
Go Faster, Webmaster
Go Faster, Webmasters
7 Habits of Exceptional Performance
High Performance Ajax Applications
Web performance optimization - MercadoLibre
Analysis of Google Page Speed Insight
The Need for Speed - SMX Sydney 2013
10 things you can do to speed up your web app today stir trek edition
High performance website
Art and Science of Web Sites Performance: A Front-end Approach
Ad

Recently uploaded (20)

PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Institutional Correction lecture only . . .
PDF
RMMM.pdf make it easy to upload and study
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Pharma ospi slides which help in ospi learning
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Cell Structure & Organelles in detailed.
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
01-Introduction-to-Information-Management.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
PPH.pptx obstetrics and gynecology in nursing
Module 4: Burden of Disease Tutorial Slides S2 2025
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
human mycosis Human fungal infections are called human mycosis..pptx
VCE English Exam - Section C Student Revision Booklet
Supply Chain Operations Speaking Notes -ICLT Program
Institutional Correction lecture only . . .
RMMM.pdf make it easy to upload and study
Microbial diseases, their pathogenesis and prophylaxis
Pharma ospi slides which help in ospi learning
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Cell Structure & Organelles in detailed.
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
01-Introduction-to-Information-Management.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPH.pptx obstetrics and gynecology in nursing

High Performance Websites

  • 1. High Performance Web Sites14 rules for faster-loading pagesParham FazelHooman NorooziniaTosan Tech Talk2011/06
  • 3. Exceptional Performancestarted in 2004quantify and improve the performance of all Yahoo! products worldwidecenter of expertisebuild tools, analyze datagather, research, and evangelize best practices
  • 4. Scopeperformance breaks into two categoriesresponse timeefficiencycurrent focus is response timeof web products
  • 5. Rough Cuts: nowHardcopy: Summer 2007http://www.oreilly.com/catalog/9780596514211/
  • 6. Steve Soudersemployer:GoogleHead Performance Engineerblog: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-endBack-end vs. Front-end
  • 10. The Performance Golden Rule80-90% of the end-user response time is spent on the front-end. Start there.Greater potential for improvement
  • 12. Proven to workSchedulePerformance Researchbreak14 RulesbreakCase StudiesLive Analysis
  • 14. perceived response timeslowcrawlboringsnailstagnantunexceptionalyawnunresponsiveimpatientdelaymoderateblahsubduedragapatheticprolongslackloadsluggishsleepylateunexcitingreducedlagcomplex heavyunmemorableobscurewhy waitperformance speed enjoyable urgentinstantaccelerateperceptionsnapachievement betterimproveaction pleasantpacequickpromoteswiftcoolmaximumdriveprompt advance fast hurryrushsatisfyingfeelexceptionalbriskrapid excitingwhat is the end user’s experience?
  • 15. User PerceptionUsability 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 RuleVilfredo Pareto: 80% of consequences come from 20% of causesFocus on the 20% that affects 80% of the end-user response time.Start at the front-end.
  • 18. 231user re-requests www.yahoo.comuser requests www.yahoo.comuser requests other web pagesEmpty vs. Full Cache
  • 19. 231user re-requests www.yahoo.comuser requests www.yahoo.comuser requests other web pagesEmpty vs. Full Cachewith an empty cache
  • 20. 231user re-requests www.yahoo.comuser requests www.yahoo.comuser requests other web pagesEmpty vs. Full Cache
  • 21. Empty vs. Full Cache21user requests www.yahoo.comuser requests other web pages3user re-requests www.yahoo.comExpires headerwith a full cache
  • 22. Empty vs. Full Cache empty cache 2.4 seconds full cache 0.9 seconds83% fewer bytes90% fewer HTTP requests
  • 23. 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 componentsinstead of pulling them from the browser disk cache.What percentage of page viewsare done with an empty cache*?http://yuiblog.com/blog/2007/01/04/performance-research-part-2/
  • 24. }1 pxAdd 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 GMTLast-Modified: Wed, 28 Sep 2006 23:49:57 GMTBrowser Cache Experiment
  • 25. Browser Cache ExperimentRequests 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 Resultsusers withempty cachepage views withempty cache40-60% ~20%
  • 28. Experiment TakeawaysKeep 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. 1user requests www.yahoo.comHTTP Quick ReviewHTTP response header sent by the web server:HTTP/1.1 200 OKContent-Type: text/html; charset=utf-8Set-Cookie: C=abcdefghijklmnopqrstuvwxyz; domain=.yahoo.com
  • 31. 1user requests www.yahoo.comHTTP Quick Review2user requests finance.yahoo.comHTTP request header sent by the browser:GET / HTTP/1.1Host: finance.yahoo.comUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; …Cookie: C=abcdefghijklmnopqrstuvwxyz;
  • 32. 31user requests autos.yahoo.comuser requests www.yahoo.comHTTP Quick ReviewHTTP request header sent by the browser:GET / HTTP/1.1Host: autos.yahoo.comUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; …Cookie: C=abcdefghijklmnopqrstuvwxyz;
  • 33. 41user requests mail.yahoo.comuser requests www.yahoo.comHTTP Quick ReviewHTTP request header sent by the browser:GET / HTTP/1.1Host: mail.yahoo.comUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; …Cookie: C=abcdefghijklmnopqrstuvwxyz;
  • 34. 51user requests tech.yahoo.comuser requests www.yahoo.comHTTP Quick ReviewHTTP request header sent by the browser:GET / HTTP/1.1Host: tech.yahoo.comUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; …Cookie: C=abcdefghijklmnopqrstuvwxyz;
  • 35. Impact of Cookies on Response Timedialup users80 ms delaykeep sizes low
  • 37. Analysis of Cookie Sizes across the Web
  • 38. Experiment Takeawayseliminate unnecessary cookieskeep cookie sizes lowset cookies at appropriate domain levelset Expires date appropriatelyearlier date or none removes cookie sooner
  • 41. Parallel DownloadsTwo in parallelFour in parallelEight in parallel
  • 45. Maximizing Parallel Downloadsresponse time (seconds)rule of thumb: use at least two but no more than four aliases
  • 46. Experiment Takeawaysconsider the effects of CPU thrashingDNS lookup times vary across ISPs and geographic locationsdomain names may not be cached
  • 47. SummaryWhat the 80/20 Rule Tells Us about Reducing HTTP Requestshttp://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 Crumbleshttp://yuiblog.com/blog/2007/01/04/performance-research-part-2/Maximizing Parallel Downloads in the Carpool Lanehttp://yuiblog.com/blog/2007/04/11/performance-research-part-4/
  • 49. 14 RulesMake fewer HTTP requestsUse a CDNAdd an Expires headerGzip componentsPut CSS at the topMove JS to the bottomAvoid CSS expressionsMake JS and CSS externalReduce DNS lookupsMinify JSAvoid redirectsRemove duplicate scriptsTurn off ETagsMake AJAX cacheable and small
  • 50. Rule 1: Make fewer HTTP requestsimage mapsCSS spritesinline imagescombined scripts, combined stylesheets
  • 51. Image mapsserver-side<a href="navbar.cgi"><img ismap src="imagemap.gif"></a>-> http://.../navbar.cgi?127,13client-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 contiguousdefining area coordinates – tedious, errorshttp://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 lessnot supported in Opera 6http://alistapart.com/articles/sprites
  • 53. Inline Imagesdata: URL schemedata:[<mediatype>][;base64],<data><IMG ALT=”Red Star”SRC="data:image/gif;base64,R0lGODlhDAAMALMLAPN8ffBiYvWWlvrKy/FvcPewsO9VVfajo+w6O/zl5estLv/8/AAAAAAAAAAAAAAAACH5BAEAAAsALAAAAAAMAAwAAAQzcElZyryTEHyTUgknHd9xGV+qKsYirKkwDYiKDBiatt2H1KBLQRFIJAIKywRgmhwAIlEEADs=">not supported in IEavoid increasing size of HTML pages:put inline images in cached stylesheetshttp://tools.ietf.org/html/rfc2397
  • 55. Combined Scripts,Combined Stylesheetscombining six scripts into one eliminates five HTTP requestschallenges: develop as separate modulesnumber of possible combinations vs. loading more than neededmaximize browser cacheone solution:dynamically combine and cache
  • 56. Rule 2: Use a CDNdistribute 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 times90%+ of browsers support compression
  • 59. Gzip compresses moreGzip supported in more browsersGzip vs. Deflate
  • 60. Gzip: not just for HTMLgzip scripts, stylesheets, XML, JSON (not images, PDF)
  • 61. Gzip Configuration Apache 2.x: mod_deflateAddOutputFilterByType DEFLATE text/html text/css application/x-javascriptHTTP requestAccept-Encoding: gzip, deflateHTTP responseContent-Encoding: gzipVary: Accept-Encodingneeded for proxies
  • 62. Gzip Edge Cases <1% of browsers have problems with gzipIE 5.5: http://support.microsoft.com/default.aspx?scid=kb;en-us;Q313712IE 6.0: http://support.microsoft.com/default.aspx?scid=kb;en-us;Q31249Netscape 3.x, 4.x http://www.schroepl.net/projekte/mod_gzip/browser.htmconsider adding Cache-Control: Privateremove ETags (Rule 13)hard to diagnose; problem getting smaller
  • 63. Rule 5: Put CSS at the top stylesheets block rendering in IEhttp://stevesouders.com/examples/css-bottom.phpsolution: put stylesheets in HEAD (per spec)avoids Flash of Unstyled Contentuse LINK (not @import)
  • 65. Rule 6: Move scripts to the bottom scripts block parallel downloads across all hostnamesscripts block rendering of everything below them in the pageIE and FFhttp://stevesouders.com/examples/js-middle.php
  • 66. Rule 6: Move scripts to the bottom script defer attribute is not a solutionblocks rendering and downloads in FFslight blocking in IEsolution: move them as low in the page as possible
  • 67. Rule 7: Avoid CSS expressions used to set CSS properties dynamically in IEwidth: expression( document.body.clientWidth < 600 ? “600px” : “auto” );problem: expressions execute many timesmouse move, key press, resize, scroll, etc.http://stevesouders.com/examples/expression-counter.php
  • 68. One-Time Expressionsexpression 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 Handlerstie behavior to (fewer) specific eventswindow.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 biggerexternal: more HTTP requests, but cachedvariablespage views per user (per session)empty vs. full cache statscomponent re-useexternal is typically betterhome pages may be an exception
  • 71. Post-Onload Downloadinline in front pagedownload external files after onloadwindow.onload = downloadComponents;function downloadComponents() { var elem = document.createElement("script"); elem.src = "http://.../file1.js"; document.body.appendChild(elem); ...}speeds up secondary pages
  • 72. Dynamic Inliningstart with post-onload downloadset cookie after components downloadedserver-side: if cookie, use externalelse, do inline with post-onload downloadcookie expiration date is keyspeeds up all pages
  • 73. Rule 9: Reduce DNS lookups typically 20-120 msblock parallel downloadsOS and browser both have DNS caches
  • 74. TTL (Time To Live)TTL – how long record can be cachedbrowser settings override TTL
  • 75. Browser DNS CacheIEDnsCacheTimeout: 30 minutesKeepAliveTimeout: 1 minuteServerInfoTimeout: 2 minutesFirefoxnetwork.dnsCacheExpiration: 1 minutenetwork.dnsCacheEntries: 20network.http.keep-alive.timeout: 5 minutesFasterfox: 1 hour, 512 entries, 30 seconds
  • 76. Reducing DNS Lookupsfewer hostnames – 2-4keep-alive
  • 77. Rule 10: Minify JavaScriptminify inline scripts, too
  • 78. Minify vs. Obfuscateminify – it's saferhttp://crockford.com/javascript/jsminhttp://dojotoolkit.org/docs/shrinksafe
  • 79. Rule 11: Avoid redirects3xx status codes – mostly 301 and 302HTTP/1.1 301 Moved PermanentlyLocation: http://stevesouders.com/newuriadd Expires headers to cache redirectsworst form of blockinghttp://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
  • 81. Avoid Redirectsmissing trailing slashhttp://astrology.yahoo.com/astrologyuse Alias or DirectorySlashmod_rewriteCNAMEslog referer – track internal linksoutbound links – harderbeacons – beware of race conditionXHR – bail at readyState 2
  • 82. Rule 12: Remove duplicate scriptshurts performanceextra HTTP requests (IE only)extra executionsatypical?2 of 10 top sites contain duplicate scriptsteam size, # of scripts
  • 83. Script Insertion Functions<?phpfunction 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 ETagsunique identifier returned in responseETag: "c8897e-aee-4165acf0"Last-Modified: Thu, 07 Oct 2004 20:54:08 GMTused in conditional GET requestsIf-None-Match: "c8897e-aee-4165acf0"If-Modified-Since: Thu, 07 Oct 2004 20:54:08 GMTif ETag doesn't match, can't send 304
  • 85. The Problem with ETagsETag for a single entity is always different across serversETag formatApache: inode-size-timestampIIS: Filetimestamp:ChangeNumberSites with >1 server return too few 304s(n-1)/nRemove themApache: FileETag noneIIS: http://support.microsoft.com/kb/922703/
  • 86. Rule 14: Make AJAX cacheable and smallXHR, JSON, iframe, dynamic scripts can still be cached, minified, and gzippeda personalized response should still be cacheable by that person
  • 87. AJAX Example: Yahoo! Mail Betaaddress 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: gzipaddress book changes infrequentlycache it; add last-modified-time in URL
  • 89. IBM Page Detailerpacket snifferWindows onlyIE, FF, any .exec:\windows\wd_WS2s.iniExecutable=(NETSCAPE.EXE),(NETSCP6.EXE),(firefox.exe)free trial, $300 licensehttp://alphaworks.ibm.com/tech/pagedetailer
  • 91. Fasterfoxmeasures load time of pagesalters config settings for faster loadingFirefox extensionfreehttp://fasterfox.mozdev.org/
  • 92. LiveHTTPHeadersview HTTP headersFirefox extensionfreehttp://livehttpheaders.mozdev.org/
  • 93. Firebugweb development evolvedinspect and edit HTMLtweak and visualize CSSdebug and profile JavaScriptmonitor network activity (caveat)Firefox extensionfreehttp://getfirebug.com/
  • 95. YSlowperformance lint toolgrades web pages for each ruleFirefox extensionYahoo! internal tool
  • 98. Takeawaysfocus on the front-endharvest the low-hanging fruityou do control user response timesLOFNO – be an advocate for your users
  • 99. Linksbook: http://www.oreilly.com/catalog/9780596514211/examples: http://stevesouders.com/examples/image maps: http://www.w3.org/TR/html401/struct/objects.html#h-13.6CSS sprites: http://alistapart.com/articles/spritesinline images: http://tools.ietf.org/html/rfc2397jsmin: http://crockford.com/javascript/jsmindojo compressor: http://dojotoolkit.org/docs/shrinksafeHTTP status codes: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.htmlIBM Page Detailer: http://alphaworks.ibm.com/tech/pagedetailerFasterfox: 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.htmlhttp://developer.yahoo.net/blog/archives/2007/04/rule_1_make_few.html