front end performance

29
Front End Performance Konstantin Käfer

Upload: konstantin-kaefer

Post on 07-May-2015

1.690 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Front End Performance

FrontEnd

PerformanceKonstantin

Käfer

Page 2: Front End Performance
Page 3: Front End Performance

Konstantin Käfer

Render a usable versionas early as possible.

3

Page 4: Front End Performance

Konstantin Käfer

Firebug’s Net panel

4

Page 5: Front End Performance

Konstantin Käfer

‣ Visualizes load order

‣ Rules

– descend as fast as possible

– as shallow as possible

– as narrow as possible

Waterfall graphs

5

Page 6: Front End Performance

Konstantin Käfer

YSlow‣ Rates a webpage based on 13 criteria

‣ Determines overall load time

‣ Provides optimization suggestions

‣ Graphs, Numbers & Figures

6

Page 7: Front End Performance

Konstantin Käfer

YSlow

7

Page 8: Front End Performance

Konstantin Käfer

YSlow is not everything.

8

Page 9: Front End Performance

Konstantin Käfer

Webpage Test‣ Automated measurement using IE

‣ Shows when rendering starts

‣ Connection view:

– http://webpagetest.org or local installation9

Page 10: Front End Performance

Konstantin Käfer

Other tools‣ IBM Page Detailer

http://www.alphaworks.ibm.com/tech/pagedetailer

‣ Pingdomhttp://tools.pingdom.com

‣ Episodeshttp://drupal.org/project/episodes

‣ Safari’s Web Inspector (Safari 4 and up)

‣ Web Debugging Proxieshttp://charlesproxy.com, http://fiddlertool.com

10

Page 11: Front End Performance

Konstantin Käfer

Waterfall diagrams

Start Connect First byte Last byte11

Page 12: Front End Performance

Konstantin Käfer

1. Reduce requests‣ Every file produces an HTTP request

‣ Fewer requests is better than smaller size

‣ HTTP 1.1: 2 components per host in parallel12

0s

15s

30s

45s

60s

0 10 20 30

RequestsSize (KB)

Page 13: Front End Performance

Konstantin Käfer

1. Reduce requests‣ Sprites

– Many images into one file

– Shift into view with background-position

‣ Aggregate scripts and styles

– Built into Drupal

– Sophisticated: http://drupal.org/project/sf_cache

‣ No redirects

13

Page 14: Front End Performance

Konstantin Käfer

1. Reduce requests‣ Caching (see 3.)

‣ Use CSS instead of images-moz-border-radius:4px;-webkit-border-radius: 4px;border-radius: 4px;

‣ data: URLs in style sheets– url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAAGXRFWHRTb2Z

0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAR9JREFUeNrEk02ORUAUhRVNJEgYsgdGbIHFsSGmhhjZAzFCRCLx906io3UROu8N+g7vPR9V95wi67oy79bXuTXP8zAMfdP48jzvCRJoihyHPcA4xRd1+V5HoZhmqZ1XWuaZtu267qWZSmKQghhKGCrZVmqqgqCQNd16g/ooI8pNOuhfuC2bX3fFwTh8nroYwrNBTxNUxzHhmHcrAf/hwbKHWa3ATYURVFRFDdwWZbYBZR75xvGbpMkefQmyzIoaRiuNE3zCGP/UNIw/FRV9RGGBkoaRhLg5yPsOA6UtM/vbfuXz0jCjc+YXvu8JwxJOCcMJ9oShtgfYXJ8VedsY0O4p+d5pmnKssyy7PGj5Pwk//6qyCfvmWU+qP+DXwIMADReKA+zC0X8AAAAAElFTkSuQmCC);

14

Page 15: Front End Performance

Konstantin Käfer

1. Reduce requests‣ Data URLs in Internet Explorer < 8:

– MHTML: http://www.phpied.com/mhtml-when-you-need-data-uris-in-ie7-and-under/

– Include encoded images as Multipart HTML– url(mhtml:http://example.com/style.css!somestring);

– Not a proven technology (fails on certain configs)

15

Page 16: Front End Performance

Konstantin Käfer

2. Use a CDN‣ Content Delivery Network

‣ Place servers near users to reduce ping time

‣ More on that in a bit

16

Page 17: Front End Performance

Konstantin Käfer

3. Caching

17

Client ServerDisabled:?

Cache

Client ServerDefault:“Still fresh”

?

Cache

Client ServerAggressive:

Cache

Full response

Partial response

Page 18: Front End Performance

Konstantin Käfer

3. Caching‣ Controlled by HTTP headers

‣ Browsers check whether content is fresh

‣ Set Expires header to a date in the far future– <Location /css>

ExpiresActive On ExpiresDefault "access plus 1 year"</Location>

‣ Drupal default: 2 weeks

‣ Change filenames/URLs when updating

18

Page 19: Front End Performance

Konstantin Käfer

4. GZip‣ Compress text content (don’t use for images!)

– <IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/css application/x-javascript</IfModule>

‣ Vastly reduces page size (often halfs)

‣ Compress scripts and styles as well

19

Page 20: Front End Performance

Konstantin Käfer

5. CSS to the top‣ == in <head>

‣ Page renders when all header CSS is loaded

‣ Loading CSS later causes re-rendering andFlash of Unstyled Content

‣ Use <link> instead of @importhttp://www.stevesouders.com/blog/2009/04/09/dont-use-import/

20

Page 21: Front End Performance

Konstantin Käfer

6. Scripts to the bottom

‣ == right before </body>

‣ Loading scripts blocks page rendering

‣ Scripts are loaded sequentially!(At least in most current browsers)

‣ Don’t use onfoo handlers in HTML code

‣ Graceful degradation

21

Page 22: Front End Performance

Konstantin Käfer

7. Minify CSS and JS‣ Remove comments and whitespace

‣ Still savings, even with GZip

‣ Drupal’s aggregator or sf_cache.module

22

Page 23: Front End Performance

Konstantin Käfer

8. Parallelization‣ “A single-user client SHOULD NOT maintain more than 2 connections with any server or proxy.” (RFC 2616, 8.1.4)

‣ Use multiple host names ➔ higher parallelization(Don’t overdo it)

‣ Most current browsers use > 2 connections

‣ http://stevesouders.com/ua/

23

Page 24: Front End Performance

Konstantin Käfer

‣ Ensure proper distribution

‣ Webpage Test graphs:

8. Parallelization

24

Page 25: Front End Performance

Konstantin Käfer

9. Reduce image weight‣ OptiPNG, PNGCrush, ...– Removes invisible content by lossless recompression

‣ JPEGtran/ImageMagick: Lossless JPEG operations

– Remove color profiles, meta data, …

‣ ImageOptim: Batch compression

‣ smushit.com – now integrated into YSlow

‣ punypng.com – supposedly more efficient

25

Page 26: Front End Performance

Konstantin Käfer

10. Lazy initialization‣ JavaScript takes time to initialize

– Libraries such as jQuery also count

– Defer setup work

‣ Only load content above the fold

– jQuery plugin: http://bit.ly/NpZPn

– Useful on image-heavy sites

‣ Don’t load invisible content (tabs) on page load

26

Page 27: Front End Performance

Konstantin Käfer

11. Other optimizations‣ “Premature optimization is the root of all evil”

—Donald Knuth

‣ Only if you have optimized everything else

‣ Strategies

– Move components to cookieless host

– Remove ETags

– Load order (see http://stevesouders.com/cuzillion/)

27