Before you surface your web app through a mobile marketplace, you should be aware of common errors and performance tips to optimize your web app for mobile devices. This session teaches you the important things you need to know, like the best practices around improving frame rate and ways to optimize . We also help you avoid mistakes, such as common cases that kill scrolling performance. Through a case study, we dive deep into the subtleties of CSS animations and improving rendering speed by reducing composite layers in your web apps. We also show you how to profile performance bottlenecks on-device using the Web App Tester tool. You get a peek into the Chromium-based web runtime on Kindle Fire devices and learn how to accommodate device rotation, touch feedback, device resolution, and screen aspect ratios to fine-tune your web app experience on mobile devices.
4. Setup
• Text Editor
• Modern Desktop Browser
• Chrome, Firefox, Safari, IE 11, etc.
• Modern Mobile Browser or Tester
• Amazon Web App Tester, Chrome, etc.
• Android SDK
• For remote debugging
Friday, November 15, 13
28. Interaction
html {
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
-webkit-user-select: none;
}
body{
-webkit-font-smoothing: antialiased; /* Fix for webkit rendering */
-webkit-text-size-adjust: 100%;
}
/* don't let "actions" dialog to come up when element is touch/held */
.prevent-action {
-webkit-touch-callout: none;
}
Friday, November 15, 13
29. Interaction continued
/* no dragging of element at all */
.content p.no-drag {
-webkit-user-drag: none;
}
/* drags entire element, not the text/selection */
.sidebar div.element-drag {
-webkit-user-drag: element;
}
/* change the character used to hide user passwords */
input[type="password"] {
-webkit-text-security: square;
}
textarea[contenteditable] {
-webkit-appearance: none;
}
Friday, November 15, 13
31. Animations
@-webkit-keyframes pulse {
from {
-webkit-transform: scale(.1);
}
to {
-webkit-transform: scale(1);
}
}
div {
-webkit-animation-name: pulse;
-webkit-animation-duration: 2s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: ease-in-out;
-webkit-animation-direction: alternate;
}
// Javascript
content.addEventListener("webkitAnimationIteration", countAnims, false);
Friday, November 15, 13
32. Transitions
// CSS
.box {
left: 40px;
-webkit-transition: all 0.3s ease-out;
}
div.box.totheleft {
-webkit-transform: translate3d(0, 0, 0);
}
div.box.totheright {
-webkit-transform: translate3d(80px, 0, 0);
}
// Javascript
window.addEventListener("webkitTransitionEnd", function() {
// Handle the end of the transition
}, false);
Friday, November 15, 13
33. Media Queries
@media screen and (orientation:portrait) {
/* portrait-specific styles */
}
@media screen and (orientation:landscape) {
/* landscape-specific styles */
}
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (minresolution: 144dpi) {
/* Style adjustments for viewports that meet the condition */
}
Friday, November 15, 13
43. Debounce Events
function SomeObject() {
var self = this;
this.lastExecThrottle = 500; // limit to one call every "n" msec
this.lastExec = new Date();
this.timer = null;
this.resizeHandler = function() {
var d = new Date();
if (d-self.lastExec < self.lastExecThrottle) {
if (self.timer) {
window.clearTimeout(self.timer);
}
self.timer = window.setTimeout(self.resizeHandler, self.lastExecThrottle);
return false; // exit
}
self.lastExec = d; // update "last exec" time
self.callResizeHandlerFunctions();
}
}
var someObject = new SomeObject();
window.onresize = someObject.resizeHandler;
Friday, November 15, 13
45. Server MIME Types
AddType text/cache-manifest .manifest
AddType text/cache-manifest .appcache
AddType application/x-web-app-manifest+json .webapp
Friday, November 15, 13
46. App cache manifest
CACHE MANIFEST
# Version 1.0
# filename: app.manifest or name.appcache
CACHE:
index.html
Game-Break.mp3
Game-Death.mp3
Game-Shot.mp3
Game-Spawn.mp3
main.js
main.css
three.min.js
...
<html manifest="app.manifest">
Friday, November 15, 13
47. W3C Web App Manifest
{
"name": "Flip.io",
"description": "Flip.io - 999 Word Puzzles. A simple, yet challenging word puzzle that
will entertain novices and lexicographers alike. Presented with 10 word definitions and
scrambled tiles of letter combos, can you find all the words?",
"launch_path": "/",
"icons": {
"60": "/flip60.png",
"128": "/flip128.png"
},
"developer": {
"name": "Russell Beattie",
"url": "http://flip.io"
},
"default_locale": "en",
"fullscreen": "true"
}
Friday, November 15, 13
48. Amazon Mobile Web App Platform Manifest
{
"verification_key": "insert your verification key from the App File(s) tab",
"launch_path": "index.html",
"permissions": [
"iap",
"geolocation",
"auth"
],
"type": "web",
"version": "0.1a",
"last_update": "2013-04-08 13:30:00-0800",
"created_by": "webappdev"
}
Friday, November 15, 13
50. Please give us your feedback on this
presentation
MBL301
As a thank you, we will select prize
winners daily for completed surveys!
Thank You
@RussB • beattier@amazon.com
developer.amazon.com/webapps
Friday, November 15, 13