Front-End Performance (with audio)

41
Front-end Performance Kornel Lesi ! ski London Web Standards 2010

description

Slides from London Web Standards talk April 2010 by Kornel Lesiński. Last slide includes 40 minutes of Q&A audio!

Transcript of Front-End Performance (with audio)

Page 1: Front-End Performance (with audio)

Front-end PerformanceKornel Lesi!skiLondon Web Standards 2010

Page 2: Front-End Performance (with audio)

Why front-end?

Every site has one

Same technologies everywhere

Page generation time—milliseconds

JavaScript execution time—milliseconds

Page loading time—seconds

Why front-end?

Page 3: Front-End Performance (with audio)

Why performance?

Page 4: Front-End Performance (with audio)

Google/Bing speed test

Delays under half a second impact business metrics

The cost of delay increases over time and persists

Number of bytes in response is less important than what they are and when they are sent

Use progressive rendering

Page 5: Front-End Performance (with audio)

Factor in Google ranking (affects 1%)

Grain of salt needed for Webmaster Tools page speed and "Let's make web faster" site

Page 6: Front-End Performance (with audio)

Nielsen’s response time limits

100ms feels instantaneous

1s keeps flow uninterrupted

10s is the limit (especially without feedback)

Page 7: Front-End Performance (with audio)

Enemy #1: Latency

Page 8: Front-End Performance (with audio)
Page 9: Front-End Performance (with audio)
Page 10: Front-End Performance (with audio)

Latency

Since modems bandwidth improved 300 times

Latency improved 3 times

Latency isn't going away

Page 11: Front-End Performance (with audio)

HTTP & TCP/IP latency

Three-way handshake: SYN, SYN-ACK, ACK

2 ping times to download anything

Pipelining unreliable

Slow start = unused bandwidth

HTTPS is much much worse

Reduce number of requests

Page 12: Front-End Performance (with audio)

Reduce number of requests

Page 13: Front-End Performance (with audio)

Merge all JavaScript files into one

don’t forget to put newlines between files

Merge all CSS files into one

don’t use @import!

use @media print

Automate this

But not in PHP!

Page 14: Front-End Performance (with audio)

CSS spritesMerge many small images into one

Use background-position

Good for hover effects

Not clipboard-friendly

Avoid huge bitmaps

Maintenance pain

Page 15: Front-End Performance (with audio)

Parallelise!

IE7 has 2 connections limit per hostname (not server)

That's what RFC2616 suggests

Use cookie-less assets sever (CDN)

Serve CSS from same host as HTML

Page 16: Front-End Performance (with audio)

Cache forevermod_expires

!"#$%&'()*)#&+$,-.&/#0.+1023+#45'+6+)&-%7

Change URL when content changes

'8)4&9:6;<=>?''

Verify cacheability

Mnot's cacheability engine redbot.org

Webkit's audit

web-sniffer.net

Page 17: Front-End Performance (with audio)

Scripts

Page 18: Front-End Performance (with audio)

@2?5,&08>3%$8& is evil

Scripts are black box. Can affect rest of the document:

A'?%$#8B

++@2?5,&08>3%$8&C1AD997EF

A/'?%$#8B

A'?%$#8+'%?G1H227BA/'?%$#8B

99B

Page 19: Front-End Performance (with audio)

@2?5,&08>3%$8& is evil

Makes parser wait for scripts

WebKit, Firefox and IE8 parse page twice

IE7 and Opera don't!

There’s no hope for scripts that write scripts

@2?5,&08>3%$8&C1A'?%$#8+'%?GI@$'-'8&%JK

Page 20: Front-End Performance (with audio)

Scripts must be at end of body

A'?%$#8+'%?B

A/L2@)B

Page 21: Front-End Performance (with audio)

@&H&%CH50?8$20CEM++@2N'85HHCEFOEF

:-%+N@&H&%%&@FH50?8$20+@&H&%CHE+M++:-%+&GN@&H&%%&@F++N@&H&%%&@G&PH50?8$20CEM&CEFHCEOQHO

@&H&%GH50?8$20CHEM'&8*$,&258CHR6EO+@&H&%CN@&H&%%&@EF+N@&H&%%&@G0544F

Page 22: Front-End Performance (with audio)

Waiting for ad.doubleclick.net…

Ads

Page 23: Front-End Performance (with audio)

Ads

Use $H%-,& otherwise

SWFObject is great

Remember embeds and buttons are same thing

Place at very end of document and use #2'$8$20Q-L'2458&

Page 24: Front-End Performance (with audio)

Don't use @&H&% attribute

Few browsers support except IE

Poor support in IE too

Quirky and not really asynchronous

@2?5,&08>3%$8& won't work anyway

-')0? is better, but beware of race conditions

Page 25: Front-End Performance (with audio)

Hosted libraries don't help

Few users have same version cached

Extra penalty if they don't

Caches are not as persistent as you think

You’ll need your own scripts file anyway

Page 26: Front-End Performance (with audio)

Waterfall

Page 27: Front-End Performance (with audio)

Waterfall

Page 28: Front-End Performance (with audio)

Waterfall

Good

Bad

Page 29: Front-End Performance (with audio)

Waterfall

IE7 and Opera differ from everything else

www.webpagetest.org

Fiddler

Enable "streaming mode"!

WebKit inspector

Firebug

Page 30: Front-End Performance (with audio)

YSlow Google PageSpeed

Page 31: Front-End Performance (with audio)

friend or foe?Progressive rendering

Page 32: Front-End Performance (with audio)

Makes slow pages faster

Makes fast pages slower

Rendering delay: load under 2s for greatness

Specify image dimensions

Specify float widths

Page 33: Front-End Performance (with audio)

Avoid clearing divs or brs!

Use overflow:hidden

Use clearfix where

overflow can't be used

Lorem ipsum. This is subliminal message. You love this presentation. Kornel is the best. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum. This is subliminal message. You love this presentation. Kornel is the best. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum. This is subliminal message. You love this presentation. Kornel is the best. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

AL%+?4&-%G-44B

Page 34: Front-End Performance (with audio)

Avoid clearing divs or brs!

Use overflow:hidden

Use clearfix where

overflow can't be used

Lorem ipsum. This is subliminal message. You love this presentation. Kornel is the best. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum. This is subliminal message. You love this presentation. Kornel is the best. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est …

Lorem ipsum. This is subliminal message. You

!"#$%&'(#)(&&*

Page 35: Front-End Performance (with audio)

Bandwidth

Page 36: Front-End Performance (with audio)

Gzip, gzip, gzip

HTML, CSS, JS—everything text-based >50% savings

Very fast, faster than network

mod_deflate/mod_compress

PHP filter

Automatically negotiated

Page 37: Front-End Performance (with audio)

Minify

10-15% users might not ask for gzip (lousy proxies, antivirs, corporate firewalls)

Makes gzipped files even smaller

YUI Compressor for CSS and JS

Google Closure Compiler advanced optimisations

Makefile is a good idea

Page 38: Front-End Performance (with audio)

Image reduction

Lowest number of colours

Don't use PNG24. If you do, try posterize

Use PNG8+alpha (Photoshop sucks. Fireworks rocks)

Don't use GIF

JPEG likes blur and 8x8 boundaries

Page 39: Front-End Performance (with audio)

pornel.net/imagealpha

ImageAlpha

Page 40: Front-End Performance (with audio)

Image optimisation

Remove unused data: comments, EXIF metadata, colour profiles (use sRGB with gamma 2.2)

Find optimal compression strategy (gzip levels and methods, PNG filters)

No loss in quality

Page 41: Front-End Performance (with audio)

ImageOptimimageoptim.pornel.net