SlideShare a Scribd company logo
Mobile Web Speed Bumps
        Don't let these problems slow your app down




Nicholas C. Zakas
Presentation Architect, Yahoo!
@slicknet
Who's this guy?




         Presentation       Contributor,
           Architect     Creator of YUI Test




Author     Lead Author   Contributor           Lead Author
http://www.flickr.com/photos/veggiefrog/3435380297/
http://www.flickr.com/photos/fkmr/48131497/
➔
          Latency
        ➔
          Device
        ➔
          Testing




http://www.flickr.com/photos/veggiefrog/3435380297/
Network latency is a time delay in delivering
         data to the client device
      Data transmission over the air always has latency
http://developer.yahoo.com/blogs/ydn/posts/2009/10/a_engineers_gui/
http://developer.yahoo.com/blogs/ydn/posts/2009/10/a_engineers_gui/
DNS




Web
DNS




Cell Co.


           Web
Mobile Web Speed Bumps
Mobile Web Speed Bumps
Mobile Web Speed Bumps
replace 'em with CSS where possible
Images
                             http://www.flickr.com/photos/calliope/83867359/
Use only CSS for simple images
Gradients | Rounded Corners | Drop Shadows | Text Shadows
Browser creates images = 0 HTTP requests
No
                                                        Images!
-webkit-border-radius: 16px;
border-radius: 16px;

-webkit-box-shadow: 0 8px 4px
rgba(192,192,192,0.5);
box-shadow: 0 8px 4px rgba(192,192,192,0.5);

background-image:-webkit-gradient(linear, 0%
0%, 0% 90%, from(rgba(64,64,64,0.75)),
to(rgba(192,192,192,0.9)));


http://www.schillmania.com/content/entries/2009/css3-and-the-future/
replace 'em with CSS where possible
Images   put 'em inline using data URIs


                             http://www.flickr.com/photos/calliope/83867359/
http://www.nczonline.net/blog/2009/10/27/data-uris-explained/
data:[<mime type>][;charset=<charset>][;base64],<encoded data>
data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7L
Zv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAA
AAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0EC
wLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFj
sVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7
<img src="data:image/gif;base64,R0lGODlhEAAOALMAAOazToeH
h0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf//
/yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0EC
wLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFj
sVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7">




    Data URIs can be embedded in HTML
           No more extra HTTP requests for images!
.icon1 {
    background: url(data:image/png;base64,<data>)
                no-repeat;
}

.icon2 {
    background: url(data:image/png;base64,<data>)
                no-repeat;
}




      Data URIs can be embedded in CSS
           No more extra HTTP requests for images!
http://www.flickr.com/photos/12714995@N03/5069508897/




                   But I already
                  have so many
                   CSS files that
                reference images!
http://github.com/nzakas/cssembed
java -jar cssembed-0.3.6.jar -o styles_data_uris.css styles.css
Data URIs are well-supported
 across smartphone browsers
http://www.flickr.com/photos/drb62/2543573955/




Data URIs not supported by
• Nokia Series 40
• Myriad/OpenWave
• Internet Explorer Mobile
• Motorola Browser
replace 'em with CSS where possible
Images   put 'em inline using data URIs
         if all else fails, make 'em small

                             http://www.flickr.com/photos/calliope/83867359/
320x480   768x1024
Large images not needed
http://tinysrc.net/
<img
src="http://i.tinysrc.mobi/http://example.com/myimage.png"
alt="My image">




    Automatically resizes images to viewport
<img
src="http://i.tinysrc.mobi/320/240/http://example.com/myima
ge.png"
 alt="My image" width="320" height="240">




    Automatically resizes image to 320x240
Mobile Web Speed Bumps
Put JavaScript and CSS inline*




* But only on first page view
Mobile Web Speed Bumps
http://m.bing.com
Request #1
  146 KB
   Request #2
     14 KB
RMSM=JApp.Home.DE384EBF~JUX.UXBaseControls.65310C41~J
UX.FrameworkCore.53E1E635~JUX.PublicJson.540180A4~JUX.Co
mpat.0907AAD4~JUX.MsCorlib.172D90C3~CUX.SiteLowRes.C8A1
DA4E~CApp.Home.FD66E1A3~CUX.Keyframes.B8625FEE~CUX.S
ite.18BDD93
RMSM=
 Japp.Home.DE384EBF~
 JUX.UXBaseControls.65310C41~
 JUX.FrameworkCore.53E1E635~
 JUX.PublicJson.540180A4~
 JUX.Compat.0907AAD4~
 JUX.MsCorlib.172D90C3~
 CUX.SiteLowRes.C8A1DA4E~
 Capp.Home.FD66E1A3~
 CUX.Keyframes.B8625FEE~
 CUX.Site.18BDD93
Mobile Web Speed Bumps
First Request



<style data-rms="save" id="CUX.Site.18BDD936"
rel="stylesheet" type="text/css">...</style>

<script data-rms="save"
id="JUX.UXBaseControls.65310C41"
type="text/javascript">...</script>
Second Request



<script
type="text/javascript">RMS.Load('CUX.Site.18B
DD936')</script>

<script
type="text/javascript">RMS.Load('JUX.UXBaseCo
ntrols.65310C41')</script>
How It Works
1. On first page load, inline all scripts and styles
2. Extract scripts and styles from page and store
   in localStorage
3. Set cookie with Ids of the scripts and styles in
   localStorage
4. On next page load, look at cookies
5. Output scripts instructing the browser to load
   that resource from localStorage
Extracting From The DOM

//extract inline script contents
var scriptNode =
        document.querySelector("script");
var scriptText = scriptNode.text;

//extract inline style contents
var styleNode =
        document.querySelector("style");
var styleText = styleNode.innerHTML;
Mobile Web Speed Bumps
40% of time
 on redirect   Download
               Redirect
➔
          Latency
        ➔
          Device
        ➔
          Testing




http://www.flickr.com/photos/veggiefrog/3435380297/
iPad 2


                                                     Droid
                           iPhone 4     Droid X    Incredible
              Mac Mini




Processor   2.2-2.4 GHz   1 GHz       1 GHz       1 GHz         1 GHz
RAM         2 GB          512 MB      512 MB      512 MB        512 MB
Storage     320-500 GB    16-32 GB    8 GB        8 GB          16-64 GB
http://www.flickr.com/photos/antonfomkin/3046849320/
Keep JavaScript small
Mobile Web Speed Bumps
Mobile Web Speed Bumps
Mobile Web Speed Bumps
All browsers now have
     optimizing JavaScript engines




Tracemonkey/    V8     Nitro   Chakra   Karakan
JaegarMonkey   (all)   (4+)     (9+)    (10.5+)
    (3.5+)
http://ie.microsoft.com/testdrive/benchmarks/sunspider/default.html
Mobile Web Speed Bumps
Mobile Web Speed Bumps
http://jeftek.com/1942/motorola-xoom-sunspider-results/
Mobile Web Speed Bumps
JavaScript Execution
         =
  CPU Processing
         =
Battery Consumption
Don't even think
  about using
  JavaScript-based
  animations

  CSS-based only




http://www.flickr.com/photos/eschipul/260392040/
Mobile Web Speed Bumps
Hardware Acceleration
    (Compositing)




  http://www.flickr.com/photos/pagedooley/3493267443/
Hardware accelerated
   CSS animations
No hardware acceleration
   before Android 3.0
Be careful with CSS
Trigger Compositing



.some-element {
    -webkit-transform: rotate(0);
}




                                    Any transform
                                       works!
http://www.flickr.com/photos/kkoshy/2825871499/




Non-composited elements work as you expect
http://www.flickr.com/photos/kkoshy/2825871499/




Composited elements become images
            in memory
http://www.flickr.com/photos/kkoshy/2825871499/




Each composited element takes up
     width x height x 4 bytes
Too many composited elements
             =
     High memory usage
             =
       Slow-moving UI
iOS doesn't support memory paging
https://bugs.webkit.org/show_bug.cgi?id=56917
CSS Gradients
(Keep 'em small)
CSS Gradients
(i.e. no full page backgrounds)
Radial gradients are heavy
        Use caution
If your app is sluggish, try
replacing CSS gradients with
     data URIs or images
Keep the DOM small
Remove unused elements
➔
          Latency
        ➔
          Device
        ➔
          Testing




http://www.flickr.com/photos/veggiefrog/3435380297/
d !
                                p e
                          a p
                    t c
               no
         r   y
   m   o
M e
http://www.blaze.io/mobile/
Mobile Web Speed Bumps
Mobile Web Speed Bumps
Mobile Web Speed Bumps
http://stevesouders.com/mobileperf/mobileperfbkm.php
Mobile Web Speed Bumps
Mobile Web Speed Bumps
Mobile Web Speed Bumps
Mobile Web Speed Bumps
Mobile Web Speed Bumps
Mobile Web Speed Bumps
http://jdrop.org
Mobile Web Speed Bumps
Mobile Web Speed Bumps
Summary
➔
          Latency
        ➔
          Device
        ➔
          Testing




http://www.flickr.com/photos/veggiefrog/3435380297/
Images | JavaScript | CSS | DOM
Balance
This is a new frontier.

The investigation has only just
started.

Test, test, test.

Share.




         http://www.flickr.com/photos/brent_nashville/201143283/
Etcetera
• My blog:
  www.nczonline.net

• Twitter:
  @slicknet

• These Slides:
  http://slideshare.net/nzakas/

More Related Content

PPTX
Browser Wars Episode 1: The Phantom Menace
PDF
Progressive Enhancement 2.0 (Conference Agnostic)
PDF
High Performance JavaScript (Amazon DevCon 2011)
PDF
[jqconatx] Adaptive Images for Responsive Web Design
PPT
Optimizing Sites for Mobile Devices
PPTX
do u webview?
PPTX
High Performance JavaScript (CapitolJS 2011)
PDF
High Performance JavaScript (YUIConf 2010)
Browser Wars Episode 1: The Phantom Menace
Progressive Enhancement 2.0 (Conference Agnostic)
High Performance JavaScript (Amazon DevCon 2011)
[jqconatx] Adaptive Images for Responsive Web Design
Optimizing Sites for Mobile Devices
do u webview?
High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (YUIConf 2010)

What's hot (20)

PDF
Prebrowsing - Velocity NY 2013
PPTX
High Performance Mobile Web
PPTX
High Performance Mobile (SF/SV Web Perf)
PDF
Going Fast on the Mobile Web
PPTX
How fast are we going now?
PDF
Don't make me wait! or Building High-Performance Web Applications
PDF
Performance on the Yahoo! Homepage
PDF
Web Page Test - Beyond the Basics
PPTX
High Performance HTML5 (SF HTML5 UG)
PPTX
HTTP 2.0 - Web Unleashed 2015
PPTX
@media - Even Faster Web Sites
PPT
Web 2.0 Expo: Even Faster Web Sites
PPTX
Enough with the JavaScript already!
PDF
PrairieDevCon 2014 - Web Doesn't Mean Slow
PDF
The Case for HTTP/2 - Internetdagarna 2015 - Stockholm
PDF
State of jQuery June 2013 - Portland
PDF
What does the browser pre-loader do?
PDF
High Performance JavaScript - WebDirections USA 2010
PDF
Web Development for UX Designers
PDF
jQuery Conference San Diego 2014 - Web Performance
Prebrowsing - Velocity NY 2013
High Performance Mobile Web
High Performance Mobile (SF/SV Web Perf)
Going Fast on the Mobile Web
How fast are we going now?
Don't make me wait! or Building High-Performance Web Applications
Performance on the Yahoo! Homepage
Web Page Test - Beyond the Basics
High Performance HTML5 (SF HTML5 UG)
HTTP 2.0 - Web Unleashed 2015
@media - Even Faster Web Sites
Web 2.0 Expo: Even Faster Web Sites
Enough with the JavaScript already!
PrairieDevCon 2014 - Web Doesn't Mean Slow
The Case for HTTP/2 - Internetdagarna 2015 - Stockholm
State of jQuery June 2013 - Portland
What does the browser pre-loader do?
High Performance JavaScript - WebDirections USA 2010
Web Development for UX Designers
jQuery Conference San Diego 2014 - Web Performance
Ad

Viewers also liked (14)

PDF
Enterprise JavaScript Error Handling (Ajax Experience 2008)
PPTX
The Pointerless Web
PDF
Progressive Enhancement 2.0 (jQuery Conference SF Bay Area 2011)
PDF
JavaScript Variable Performance
PDF
Nicholas' Performance Talk at Google
PPT
Responsive interfaces
PDF
Test Driven Development With YUI Test (Ajax Experience 2008)
PPTX
Scalable JavaScript Application Architecture 2012
PDF
High Performance JavaScript 2011
PDF
Scalable JavaScript Application Architecture
PPTX
JavaScript APIs you’ve never heard of (and some you have)
PDF
Speed Up Your JavaScript
PPTX
Maintainable JavaScript 2012
PDF
Writing Efficient JavaScript
Enterprise JavaScript Error Handling (Ajax Experience 2008)
The Pointerless Web
Progressive Enhancement 2.0 (jQuery Conference SF Bay Area 2011)
JavaScript Variable Performance
Nicholas' Performance Talk at Google
Responsive interfaces
Test Driven Development With YUI Test (Ajax Experience 2008)
Scalable JavaScript Application Architecture 2012
High Performance JavaScript 2011
Scalable JavaScript Application Architecture
JavaScript APIs you’ve never heard of (and some you have)
Speed Up Your JavaScript
Maintainable JavaScript 2012
Writing Efficient JavaScript
Ad

Similar to Mobile Web Speed Bumps (20)

PDF
Developing for Mobile
PDF
Extreme Web Performance for Mobile Devices - Velocity Barcelona 2014
PDF
Extreme Web Performance for Mobile Devices - Velocity NY
PDF
The Mobile Web - HTML5 on mobile devices
PDF
Extreme Web Performance for Mobile Device Fluent 2015
PDF
Building cross platform mobile web apps
KEY
HTML5 apps for iOS (and probably beyond)
PPTX
Mobile for web developers
PDF
HTML5 and the dawn of rich mobile web applications
PDF
That's Web? Extreme Optimization for the Mobile Web (Oct 2012)
PPTX
Html5 on Mobile(For Developer)
PDF
Mobile Web Performance - Getting and Staying Fast
PDF
Extreme Web Performance for Mobile Devices
KEY
Faster Frontends
KEY
Js On Mobile Devices
PDF
Mobile App Development
PDF
Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18
PDF
Mobile Web Performance - Velocity 2011
KEY
HTML5와 모바일
PPTX
Phonegap - An Introduction
Developing for Mobile
Extreme Web Performance for Mobile Devices - Velocity Barcelona 2014
Extreme Web Performance for Mobile Devices - Velocity NY
The Mobile Web - HTML5 on mobile devices
Extreme Web Performance for Mobile Device Fluent 2015
Building cross platform mobile web apps
HTML5 apps for iOS (and probably beyond)
Mobile for web developers
HTML5 and the dawn of rich mobile web applications
That's Web? Extreme Optimization for the Mobile Web (Oct 2012)
Html5 on Mobile(For Developer)
Mobile Web Performance - Getting and Staying Fast
Extreme Web Performance for Mobile Devices
Faster Frontends
Js On Mobile Devices
Mobile App Development
Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18
Mobile Web Performance - Velocity 2011
HTML5와 모바일
Phonegap - An Introduction

More from Nicholas Zakas (8)

PPTX
JavaScript Timers, Power Consumption, and Performance
PDF
Maintainable JavaScript 2011
PDF
YUI Test The Next Generation (YUIConf 2010)
PDF
High Performance JavaScript - Fronteers 2010
PDF
High Performance JavaScript - jQuery Conference SF Bay Area 2010
PDF
Extreme JavaScript Compression With YUI Compressor
PDF
Maintainable JavaScript
ODP
The New Yahoo! Homepage and YUI 3
JavaScript Timers, Power Consumption, and Performance
Maintainable JavaScript 2011
YUI Test The Next Generation (YUIConf 2010)
High Performance JavaScript - Fronteers 2010
High Performance JavaScript - jQuery Conference SF Bay Area 2010
Extreme JavaScript Compression With YUI Compressor
Maintainable JavaScript
The New Yahoo! Homepage and YUI 3

Recently uploaded (20)

PDF
Review of recent advances in non-invasive hemoglobin estimation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Electronic commerce courselecture one. Pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
NewMind AI Monthly Chronicles - July 2025
PPT
Teaching material agriculture food technology
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Advanced Soft Computing BINUS July 2025.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Network Security Unit 5.pdf for BCA BBA.
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
Review of recent advances in non-invasive hemoglobin estimation
“AI and Expert System Decision Support & Business Intelligence Systems”
Electronic commerce courselecture one. Pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
NewMind AI Monthly Chronicles - July 2025
Teaching material agriculture food technology
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Unlocking AI with Model Context Protocol (MCP)
Advanced Soft Computing BINUS July 2025.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Network Security Unit 5.pdf for BCA BBA.
The AUB Centre for AI in Media Proposal.docx
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
20250228 LYD VKU AI Blended-Learning.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing

Mobile Web Speed Bumps