Mobile Web Speed Bumps
Upcoming SlideShare
Loading in...5

Mobile Web Speed Bumps



As browsers explode with new capabilities and migrate onto devices users can be left wondering, “what’s taking so long?” Learn how HTML, CSS, JavaScript, and the web itself conspire against a ...

As browsers explode with new capabilities and migrate onto devices users can be left wondering, “what’s taking so long?” Learn how HTML, CSS, JavaScript, and the web itself conspire against a fast-running application and simple tips to create a snappy interface that delight users instead of frustrating them.



Total Views
Views on SlideShare
Embed Views



29 Embeds 4,472 3390 542 296 70 40 32 25 17 10 8 5 5 4 4 3 3 3 2 2 2 1 1 1
http://moderation.local 1 1 HTTP 1 HTTP 1 HTTP 1 1



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • Most excellent! I was just looking for info on data uri's on mobile (and where they're not supported), as well as memory/performance impact on CSS composited elements/images. Hopefully I'll have the chance to hear you present one day as there's always so much info that simply can't be passed via a slide deck.

    Thanks for sharing!
    Are you sure you want to
    Your message goes here
  • Great presentation at web directions.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Mobile Web Speed Bumps Mobile Web Speed Bumps Presentation Transcript

  • Mobile Web Speed Bumps Dont let these problems slow your app downNicholas C. ZakasPresentation Architect, Yahoo!@slicknet
  • Whos this guy? Presentation Contributor, Architect Creator of YUI TestAuthor Lead Author Contributor Lead Author
  • ➔ Latency ➔ Device ➔ Testing
  • Network latency is a time delay in delivering data to the client device Data transmission over the air always has latency
  • DNSWeb
  • DNSCell Co. Web
  • replace em with CSS where possibleImages
  • Use only CSS for simple imagesGradients | 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 4pxrgba(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)));
  • replace em with CSS where possibleImages put em inline using data URIs
  • data:[<mime type>][;charset=<charset>][;base64],<encoded data>
  • data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7
  • <img src="data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/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!
  • But I already have so many CSS files that reference images!
  • java -jar cssembed-0.3.6.jar -o styles_data_uris.css styles.css
  • Data URIs are well-supported across smartphone browsers
  • URIs not supported by• Nokia Series 40• Myriad/OpenWave• Internet Explorer Mobile• Motorola Browser
  • replace em with CSS where possibleImages put em inline using data URIs if all else fails, make em small
  • 320x480 768x1024
  • Large images not needed
  • <imgsrc=""alt="My image"> Automatically resizes images to viewport
  • <imgsrc="" alt="My image" width="320" height="240"> Automatically resizes image to 320x240
  • Put JavaScript and CSS inline** But only on first page view
  • Request #1 146 KB Request #2 14 KB
  • 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
  • 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
  • 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<scripttype="text/javascript">RMS.Load(CUX.Site.18BDD936)</script><scripttype="text/javascript">RMS.Load(JUX.UXBaseControls.65310C41)</script>
  • How It Works1. On first page load, inline all scripts and styles2. Extract scripts and styles from page and store in localStorage3. Set cookie with Ids of the scripts and styles in localStorage4. On next page load, look at cookies5. Output scripts instructing the browser to load that resource from localStorage
  • Extracting From The DOM//extract inline script contentsvar scriptNode = document.querySelector("script");var scriptText = scriptNode.text;//extract inline style contentsvar styleNode = document.querySelector("style");var styleText = styleNode.innerHTML;
  • 40% of time on redirect Download Redirect
  • ➔ Latency ➔ Device ➔ Testing
  • iPad 2 Droid iPhone 4 Droid X Incredible Mac MiniProcessor 2.2-2.4 GHz 1 GHz 1 GHz 1 GHz 1 GHzRAM 2 GB 512 MB 512 MB 512 MB 512 MBStorage 320-500 GB 16-32 GB 8 GB 8 GB 16-64 GB
  • Keep JavaScript small
  • All browsers now have optimizing JavaScript enginesTracemonkey/ V8 Nitro Chakra KarakanJaegarMonkey (all) (4+) (9+) (10.5+) (3.5+)
  • JavaScript Execution = CPU Processing =Battery Consumption
  • Dont even think about using JavaScript-based animations CSS-based only
  • Hardware Acceleration (Compositing)
  • 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!
  • elements work as you expect
  • elements become images in memory
  • composited element takes up width x height x 4 bytes
  • Too many composited elements = High memory usage = Slow-moving UI
  • iOS doesnt support memory paging
  • CSS Gradients(Keep em small)
  • CSS Gradients(i.e. no full page backgrounds)
  • Radial gradients are heavy Use caution
  • If your app is sluggish, tryreplacing CSS gradients with data URIs or images
  • Keep the DOM smallRemove unused elements
  • ➔ Latency ➔ Device ➔ Testing
  • d ! p e a p t c no r y m oM e
  • Summary
  • ➔ Latency ➔ Device ➔ Testing
  • Images | JavaScript | CSS | DOM
  • BalanceThis is a new frontier.The investigation has only juststarted.Test, test, test.Share.
  • Etcetera• My blog:• Twitter: @slicknet• These Slides: