Mobile Web Performance
maddesigns | Sven Wolfermann
Desknots Berlin Meetup, 17.10.2012
maddesigns | Sven Wolfermann
Desknots Berlin Meetup, 17.10.2012
http://developer.yahoo.com/performance/rules.html
Phones aren't Laptops
impossible to optimize for all browsers/devices
Each host is a different lookup
time waste only through latency:
via DSL + WLAN: 33 ms + 20 ms + 5 ms = 58 ms
via UMTS: 33 ms + 175 ms = 208 ms
<script src="foo+bar+baz.js"></script>
<head>
and on followed pages via <link>
and <script src>
for caching
localStorage
for CSS & JavaScriptno images needed
but CSS gradients were painted onload, images are external resources
Recalculating / Repainting the UI
be careful!
use the right format!
left: JPEG, 500x508, quality=60, size=87802
right: JPEG, 1000x1015, quality=15, size=83150 (file size -5%)
|
|||
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
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>
<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>
<IfModule mod_deflate.c> <FilesMatch "\.(js|css)$"> SetOutputFilter DEFLATE </FilesMatch> </IfModule>
<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">
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);