1. John Arne Sæterås
Twitter: @jonarnes
Head of innovation at Mobiletech
http://www.slideshare.net/jonarnes/
August 18, 2010
YEP, WEB ON MOBILE IS SLOW
fredag 7. juni 13
2. 100 ms faster:
1% increased revenue
1 sec delay:
2.8% drop in revenue
http://www.slideshare.net/stubbornella/designing-fast-websites-presentation
http://slideshare.net/markstanton/speed-matters
SLOW IS NOT COOL
...even less cool on mobile
fredag 7. juni 13
3. THE VALUE CHAIN
developer server internet telco
network device
Doesn’t really make things more
difficult, but reveal a few issues
browser
fredag 7. juni 13
4. WHY IS MOBILE SLOWER?
• Network Latency
• Available Bandwidth
• The Implementation
• Processing Power
• Browser
• Battery Preserving Strategies
fredag 7. juni 13
6. 1.4 MB
4%9%
7%
3%
16% 61%
Images Scripts
CSS Flash
Other HTML
in 92 requests on average
http://httparchive.org/
fredag 7. juni 13
7. 1.4 MB
in 92 requests on average
• Avg. speed: 2Mbps (cisco)
• 1 Mbps = 0.12 MB/s
• 1.4 / 0.24 = 6s
6Seconds
download
time
Hold that thought...
more on this later.
http://www.cisco.com/en/US/solutions/collateral/ns341/ns525/ns537/ns705/ns827/white_paper_c11-520862.html
fredag 7. juni 13
8. 1.4 MB
in 92 requests on average
•100-200 ms pr roundtrip
•Depends....(DNS, pipelining,
concurrentTCP connections
etc.)
9,1Seconds
latency in
total
Hold that thought...
more on this now.
fredag 7. juni 13
13. SERVE A PAGE TO A
MOBILE DEVICE IN
LESS THAN 1 SECOND?
A great overview by Ilyva Gricorik:
bit.ly/mobile-barrier
fredag 7. juni 13
14. 1.4 MB
in 92 requests on average
•Wake up radio (one time)
•TCP and DNS (one time)
•92 round trips (6 req pr conn.)
•Downloading 1.4 mb over 2Mbps
10,1Seconds
total
+ rendering time in the browser
+ server response time
Disclaimer: lots of assumptions in this calculation!
fredag 7. juni 13
16. Load time: 9.7 s
Size: 1.6 MB
Load time: 9.1 s
Size: 1.2 MB
fredag 7. juni 13
17. WHO CARES?
The users care!
Telco Network
53,53 %
Other
46,47 %
How users connect. Page views per
connection type. (Scandinavian Countries).
Source: Mobiletech
fredag 7. juni 13
21. RESPONSIVE
WEB DESIGN
Doh...
Much smaller
6%
Same size
72%
Smaller
22%
http://www.guypo.com/uncategorized/real-world-rwd-performance-take-2/
Also about the same
number of
HTTP requests
fredag 7. juni 13
22. RWD IS A TECHNIQUE
Nothing wrong with the technique! It is brilliant!
The famous Iceberg: @brad_frost
fredag 7. juni 13
23. RWD != MOBILE OPTIMIZED
but an important step in the right direction
fredag 7. juni 13
24. Load time: 3.81s
Size: 135.20 kb
Load time: 2.36 s
Size: 36.59 kb
More on how the built the new BBC News site: http://slidesha.re/14IYNOO
fredag 7. juni 13
39. PURPOSE OF RESS
• Reduce need for client side
processing
• Eliminate “over downloading”
fredag 7. juni 13
40. INGREDIENTS OF RESS
Hello, I know exactly how to
make you shine!
Information about the
requesting device
Request/Response
fredag 7. juni 13
41. NOT A CRIME!
82% of top 100 Alexa sites
use Device Detection
In the case of
Mashable, we also
detect the type of
device and change
the site’s behavior
accordingly.
“
”
http://www.circleid.com/posts/20120111_analysis_of_server_side_mobile_web_detection/
http://mashable.com/2012/12/11/responsive-web-design/
fredag 7. juni 13
42. THERE IS A DIFFERENCE
User-Agent sniffing
var
isiPhone
=
/iPhone/i.test(navigator.userAgent);
Feature Detection
var
appCache=
function()
{
return
!!window.applicationCache;
};
Device Detection
GET
http://ddr.demo.wew.io/c/dual_orientation
Using the User-Agent as a key to look up in a data base.
fredag 7. juni 13
44. FEATURES OF A DDR
• Nice place to store “tacit knowledge”
• “Business rules”
• Specifics to your site
• Override feature detected features
• If a feature works, but not well enough to make it useable
• False positives (not a HUGE issue, but still)
• Available server side too
• Adapt and optimize stuff before sending to client
Device Description
Repository
fredag 7. juni 13
45. EXAMPLE
if
($type_of_device
==
”smartTV”)
include(TVnav.php);
else
include(nav.php);
http://www.circleid.com/posts/20120111_analysis_of_server_side_mobile_web_detection/
fredag 7. juni 13
48. DEVICE DETECTION
Single Capability
Request
GET
http://ddr.demo.wew.io/c/model_name
Response
{"model_name":"iPhone"}
Capability Sets
Request
GET
http://ddr.demo.wew.io/cset/mySet
Response
{"capa1":"first
capa
value","capa2":"second
capa
value"
...}
Examples and documentation: https://github.com/whateverweb/device-detection
fredag 7. juni 13
49. EXAMPLE
var
http
=
new
XMLHttpRequest();
http.open("GET",
"http://ddr.demo.wew.io/c/brand_name",
true);
http.onreadystatechange
=
function()
{
if
(http.readyState
==
4)
console.log(http.responseText);
}
http.send();
fredag 7. juni 13
50. EXAMPLE
public
function
get($capa){
foreach(getallheaders()
as
$key
=>
$value)
{
if
($key
!="Host")
$this-‐>headers[]
=
$key
.
':
'
.
$value;
}
$url
=
$this-‐>service
.
$capa;
$curl
=
curl_init($url);
curl_setopt($curl,
CURLOPT_RETURNTRANSFER,
true);
curl_setopt($curl,
CURLOPT_HTTPHEADER,
$this-‐>headers);
$this-‐>response
=
curl_exec($curl);
curl_close($curl);
return
json_decode($this-‐>response)-‐>$capa;
}
fredag 7. juni 13
52. EXAMPLE
<div
data-‐picture
data-‐alt="A
beautiful
butterfly">
<div
data-‐src="http://img.demo.wew.io/px_100/http://exampe.com/image.png"></div>
<div
data-‐src="http://img.demo.wew.io/px_320/http://exampe.com/image.png"
data-‐media="(min-‐width:
320px)"></div>
<div
data-‐src="http://img.demo.wew.io/px_320/@_2/http://exampe.com/image.png"
data-‐media="(min-‐width:
320px)
and
(-‐webkit-‐min-‐device-‐pixel-‐ratio:
2.0)"></div>
<noscript>
<img
src="http://img.demo.wew.io/px_10/http://exampe.com/image.png">
</noscript>
</div>
Picturefill: https://github.com/scottjehl/picturefill. Full example: https://github.com/whateverweb/Image-Server/blob/master/examples/picturefill/index.html
Using Picturefill
fredag 7. juni 13
53. CSS OPTIMIZATION
Device Capabilities as Media Features
Removing overhead and excess styles
Examples and documentation: https://github.com/whateverweb/CSS-processor
@media
(-‐wew-‐pointing-‐method:
touchscreen){
a
{
padding:
10px;
}
}
@media
all
and
(min-‐width:
1500px){
//removed
for
devices
where
1500px
is
impossible.
e.g.
iPhones
body{color:
green;}
}
Server Side rendering
fredag 7. juni 13
55. EXAMPLE
<!doctype
html>
<html>
<head>
<link
rel="stylesheet"
href="//css.demo.wew.io/http://example.com/style.css”/>
</head>
<body>
<img
src="http://img.demo.wew.io/http://example.com/image.jpg"/>
<script>
var
w=new
wew();
w.getSet("myset",cb);
</script>
</body>
</html>
•Markup lives anywhere
•CSS and images are proxied,
optimized and cached
•Device data available clientside
fredag 7. juni 13
62. THE RULES
1. Make Fewer HTTP Requests
2. Use a Content Delivery Network
3. Add an Expires Header
4. Gzip Components
5. Put Stylesheets at theTop
6. Put Scripts at 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
14.Make AJAX Cacheable
By Steve Souders: http://stevesouders.com/hpws/rules.php
fredag 7. juni 13
63. BASICALLY SAYS
• Make as few HTTP requests as possible
• Reduce the size of what is downloaded
• Make page rendering fast
fredag 7. juni 13
64. MORE TIPS
• Don’t wake the radio
• Inline more that feels natural
• Use the server!
What about “eternal
scrolling”
Inline “structural”
CSS and jsDon’t let the browser
decide everything
fredag 7. juni 13