300 likes | 392 Views
Even Faster Web Sites. http://stevesouders.com/docs/wikipedia-20090812.ppt Disclaimer: This content does not necessarily reflect the opinions of my employer. the importance of frontend performance. 9%. 91%. 17%. 83%. iGoogle, primed cache. iGoogle, empty cache. Make fewer HTTP requests
E N D
Even Faster Web Sites http://stevesouders.com/docs/wikipedia-20090812.ppt Disclaimer: This content does not necessarily reflect the opinions of my employer.
the importance of frontend performance 9% 91% 17% 83% iGoogle, primed cache iGoogle, empty cache
Make fewer HTTP requests • Use a CDN • Add an Expires header • Gzip components • Put stylesheets at the top • Put scripts at the bottom • Avoid CSS expressions • Make JS and CSS external • Reduce DNS lookups • Minify JS • Avoid redirects • Remove duplicate scripts • Configure ETags • Make AJAX cacheable 14 Rules
Even Faster Web Sites Splitting the initial payload Loading scripts without blocking Coupling asynchronous scripts Positioning inline scripts Sharding dominant domains Flushing the document early Using iframes sparingly Simplifying CSS Selectors Understanding Ajax performance..........Doug Crockford Creating responsive web apps............Ben Galbraith, Dion Almaer Writing efficient JavaScript.............Nicholas Zakas Scaling with Comet.....................Dylan Schiemann Going beyond gzipping...............Tony Gentilcore Optimizing images...................Stoyan Stefanov, Nicole Sullivan
Why focus on JavaScript? Yahoo! Wikipedia eBay AOL MySpace YouTube Facebook
scripts block <script src="A.js"> blocks parallel downloads and rendering 9 secs: IE 6-7, FF 3.0, Chr 1, Op 9-10, Saf 3 7 secs: IE 8, FF 3.5(?), Chr 2, Saf 4
initial payload and execution 26% avg 252K avg
splitting the initial payload split your JavaScript between what's needed to render the page and everything else load "everything else" after the page is rendered separate manually (Page Speed); tools needed to automate this (Doloto) load scripts without blocking – how?
MSN.com: parallel scripts MSN Scripts and other resources downloaded in parallel! How? Secret sauce?! var p= g.getElementsByTagName("HEAD")[0]; var c=g.createElement("script"); c.type="text/javascript"; c.onreadystatechange=n; c.onerror=c.onload=k; c.src=e; p.appendChild(c)
Loading Scripts Without Blocking XHR Eval XHR Injection Script in Iframe Script DOM Element Script Defer document.write Script Tag
Load Scripts Without Blocking *Only other document.write scripts are downloaded in parallel (in the same script block).
and the winner is... XHR Eval XHR Injection Script in iframe Script DOM Element Script Defer same domains different domains Script DOM Element Script Defer no order preserve order XHR Eval XHR Injection Script in iframe Script DOM Element (IE) Script DOM Element (FF) Script Defer (IE) Managed XHR Eval Managed XHR Injection no order preserve order Script DOM Element no busy show busy Script DOM Element (FF) Script Defer (IE) Managed XHR Injection Managed XHR Eval Script DOM Element (FF) Script Defer (IE) Managed XHR Eval Managed XHR Injection no busy show busy XHR Injection XHR Eval Script DOM Element (IE) Managed XHR Injection Managed XHR Eval Script DOM Element
Loading Scripts Without Blocking don't let scripts block other downloads you can still control execution order, busy indicators, and onload event What about inline scripts?
bad: stylesheet followed by inline script browsers download stylesheets in parallel with other resources that follow... ...unless the stylesheet is followed by an inline script http://stevesouders.com/cuzillion/?ex=10021 best to move inline scripts above stylesheets or below other resources use Link, not @import
mispositioned inline scripts MSN Wikipedia eBay MySpace
going beyond gzipping Tony Gentilcore, Chapter 9, Even Faster Web Sites Rule 4: Gzip Components from HPWS HTTP/1.1 • request: Accept-Encoding: gzip,deflate • response: Content-Encoding: gzip Apache 2.x: • AddOutputFilterByType DEFLATE text/html text/css application/x-javascript
benefits of gzipping 70% reduction in transfer size not just for HTML!! • all text: JavaScript, CSS, XML, JSON • not binary: images, PDF, Flash
so what's the issue? 15% of users get uncompressed responses surprize! why? old browsers? no • Netscape Navigator 3 – 0.0% • Netscape Communicator 4 – 0.1% • Opera 3.5 – 0.0% • IE <3 – 0.01% clue: most prevalent in the Middle East
who's stripping? proxies and anti-virus software disable compression for easier response filtering
what to do Thanks, Tony! see Tony's chapter in Even Faster Web Sites don't assume compression go the extra mile to reduce response size • event delegation (-5%)* • relative URLs (-3%) • minify HTML, JavaScript, and CSS (-4%) • use CSS rules over inline styles (-1%) • alias long JavaScript symbol names (??) * Results of applying each technique to the Alexa top ten
White Dwarf http://en.wikipedia.org/wiki/White_dwarf
White Dwarf combine stylesheets remove unused CSS (50%) sprite 8 bg images combine scripts minify (36K, 36%) move lower load async 81% deferrable move inline script add Expires to upload.w.o don't use querystring: ?233yz http://en.wikipedia.org/wiki/White_dwarf
combine stylesheets remove unused CSS (50%) move inline script combine scripts minify (44K, 35%) move lower load async 76% deferrable add Expires to upload.w.o don't use querystring: ?233yz don't change URL: 233yz v 233zz
takeaways focus on the frontend run YSlow (http://developer.yahoo.com/yslow) and Page Speed! (http://code.google.com/speed/page-speed/) speed matters
impact on revenue +2000 ms -4.3% revenue/user1 +400 ms -5-9% full-page traffic2 +400 ms -0.59% searches/user1 fastest users+50% page views3 -5000 ms +7-12% revenue4 1 http://en.oreilly.com/velocity2009/public/schedule/detail/8523 2 http://www.slideshare.net/stoyan/yslow-20-presentation 3 http://en.oreilly.com/velocity2009/public/schedule/detail/7579 4 http://en.oreilly.com/velocity2009/public/schedule/detail/7709 Bing: Yahoo: Google: AOL: Shopzilla:
cost savings hardware – reduced load • Shopzilla – 50% fewer servers bandwidth – reduced response size http://billwscott.com/share/presentations/2008/stanford/HPWP-RealWorld.pdf
if you want • better user experience • more revenue • reduced operating expenses the strategy is clear Even Faster Web Sites
Steve Souders souders@google.com http://stevesouders.com/docs/wikipedia-20090812.ppt