Mobile Web Performance

maddesigns | Sven Wolfermann
Desknots Berlin Meetup, 17.10.2012

Introducing me

Performance History (in short)

 

13 Performance Rules by Yahoo -> Yslow

http://developer.yahoo.com/performance/rules.html

 

Google Page Speed

https://developers.google.com/speed/pagespeed

Yslow Rules (classic)

  1. Make Fewer HTTP Requests
  2. Use a Content Delivery Network
  3. Add an Expires Header
  4. Gzip Components
  5. Put CSS at the Top
  6. Move Scripts to the Bottom
  7. Avoid CSS Expressions
  8. Make JavaScript and CSS External
  9. Reduce DNS Lookups
  10. Minify JavaScript
  11. Avoid Redirects
  12. Remove Duplicate Scripts
  13. Configure ETags

Mobile Web Performance

Why is performance on mobile even more important?

Rendering

 

Device limitations

Phones aren't Laptops

Mobile Browser Fragmentation

impossible to optimize for all browsers/devices

Latency

DNS / HTTP Requests

Each host is a different lookup

Latency

Latency from Hamburg – Munich – Hamburg

time waste only through latency:

via DSL + WLAN: 33 ms + 20 ms + 5 ms = 58 ms

via UMTS: 33 ms + 175 ms = 208 ms

Reduce Requests

  • 2 Requests less
Yellow: Time for Requests. Blue: Download of file.

mobile Network

UI Performance

Use CSS3 whereever you can

no images needed

Benefits

be careful with CSS3

large radial gradients

be careful with CSS3

large radial gradients

but CSS gradients were painted onload, images are external resources

be careful with CSS3

Recalculating / Repainting the UI

box-shadow: inset

 

background-size: cover

 

be careful!

text-indent

Optimizing Images

Images

use the right format!

JPG for pictures! -> JPEGmini

Retina JPGs

left: JPEG, 500x508, quality=60, size=87802
right: JPEG, 1000x1015, quality=15, size=83150 (file size -5%)

SVG

 

SVG

7,57 KB

51,50 KB

4,50 KB

 

PNG 200px

6,50 KB

11,10 KB

4,18 KB

PNG 400px

11,80 KB

27,60 KB

8,32 KB

PNG 800px

18,50 KB

72,70 KB

14,80 KB

bold = PNG smaller than SVG

CSS Sprites

Data URI

HTML

<img src="logo-maddesigns.png" alt="Logo maddesigns">

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhE...">

CSS

<style>
  .logo { background-image: url("logo-maddesigns.png") }
</style>

<style>
  .logo { background-image: url("data:image/png;base64,iVBORw...")}
</style>

Data URI

Drawbacks

Caching

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css                 "access plus 1 week"
ExpiresByType application/javascript   "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType image/gif                "access plus 1 month"
ExpiresByType image/jpeg               "access plus 1 month"
ExpiresByType image/png                "access plus 1 month"
</IfModule>

or other way round

<IfModule mod_expires.c>
  ExpiresActive on

  ExpiresDefault                          "access plus 1 month"

  ExpiresByType text/html                 "access plus 0 seconds"
  ExpiresByType text/xml                  "access plus 0 seconds"
  ExpiresByType application/xml           "access plus 0 seconds"
  ExpiresByType application/json          "access plus 0 seconds"
  ExpiresByType text/cache-manifest       "access plus 0 seconds"
</IfModule>

GZIPing

<IfModule mod_deflate.c>
  <FilesMatch "\.(js|css)$">
    SetOutputFilter DEFLATE
  </FilesMatch>
</IfModule>
  

Resposive Images
could be another full session, so just a quick overview...

Adaptive Images

Responsive Images Service – ReSRC.it

Resposive Images – a looooooong story

<picture> element

<picture alt="angry pirate">
  <source src=hires.png media="min-width:800px">
  <source src=midres.png media="min-width:480px">
  <source src=lores.png>
  <!-- fallback for browsers without support -->
  <img src=midres.png alt="angry pirate">
</picture>
  

srcset

<img src="face-600-200-at-1.jpg" alt=""
     srcset="face-600-200-at-1.jpg 600w 200h 1x,
             face-600-200-at-2.jpg 600w 200h 2x,
             face-icon.png 200w 200h">

New CSS Image Set

available prefixed in iOS6, Safari 6 and Chrome 21

adressing HiDPI Screens

background-image: -webkit-image-set(url(low.png) 1x, url(hi.jpg) 2x);

Testtools

Thank you for your attention!