high performance mobile web

54
High Performance Mobile Web Morgan Cheng Feb 17 th , 2012

Upload: mocheng

Post on 08-May-2015

6.242 views

Category:

Technology


2 download

DESCRIPTION

My Last Tech Talk at Yahoo!

TRANSCRIPT

Page 1: High Performance Mobile Web

High Performance Mobile Web

Morgan ChengFeb 17th, 2012

Page 2: High Performance Mobile Web

It is Mobile

Page 3: High Performance Mobile Web

Mobile AppMobile Web

Page 4: High Performance Mobile Web

User

The Middle Man

Developer

Page 5: High Performance Mobile Web

Multiple Platforms

Page 6: High Performance Mobile Web

Mobile Web: Cross Platform Solution

Page 7: High Performance Mobile Web

Modern Mobile is Blessed with HTML5

Page 8: High Performance Mobile Web

http://blog.sc5.fi/2012/01/html5-web-app-architecture-explained/

Architecture

Page 9: High Performance Mobile Web

These Best Practices Still Work?

http://developer.yahoo.com/performance/rules.html

Page 10: High Performance Mobile Web

More Tips

Page 11: High Performance Mobile Web

Deal With Designer

Page 12: High Performance Mobile Web
Page 13: High Performance Mobile Web

In the Eyes of Designer

Beautiful Radial Gradient

Smooth Rotating

Stereovision created by shadow

Page 14: High Performance Mobile Web

In the Eyes of Developer

The Background Image Might Hurt Performance

What’s the rotating center, radius and angle?

Should The Shadow Be CSS or Image?

Page 15: High Performance Mobile Web

Balance For Perfect

Page 16: High Performance Mobile Web

Cache is Limited

Page 17: High Performance Mobile Web

http://www.stevesouders.com/blog/2010/07/12/mobile-cache-file-sizes/

Page 18: High Performance Mobile Web

Always Minify Your Resources

Page 19: High Performance Mobile Web

Cookie + LocalStorage

Page 20: High Performance Mobile Web

More HTTP Requests Mean Slower

Page 21: High Performance Mobile Web

First Visit

Server BrowserBig HTML LocalStorageResources

With inline JS, CSS and data-URI

Extract Resources and Save to LocalStorage; Set Cookie

Without Cookie

Page 22: High Performance Mobile Web

Second Visit

Server BrowserBig HTML LocalStorage

With reference to keys in LocalStorage

Load Resources and Insert into DOM

With Cookie

Resources

Page 23: High Performance Mobile Web

Favor transition over timer

Page 24: High Performance Mobile Web

Animation with Timer

Change Element’s Style with setTimeout Browser Has No Idea What is Actually Doing

http://jsfiddle.net/r5mYr/

Page 25: High Performance Mobile Web

Animation with Transition

Let Browser Know It is Animationhttp://jsfiddle.net/Rapvs/

Page 26: High Performance Mobile Web

Animation with Transition

Let Browser Know It is Animationhttp://jsfiddle.net/Rapvs/

With transform, it is betterhttp://jsfiddle.net/DwtCc/

Page 27: High Performance Mobile Web

Be Careful With CSS3

Page 28: High Performance Mobile Web

-webkit-gradient-webkit-box-shadow

Static Images Render Faster

Page 29: High Performance Mobile Web

Background Image + ARIA

Page 30: High Performance Mobile Web

background-image Faster Than <img>

<img src=“photo.png” alt=“One Photo”>

<div id=“photo”></div>#photo {

background-image: url(photo.png);}

Page 31: High Performance Mobile Web

background-image only break the semantics

Page 32: High Performance Mobile Web

background-image Faster Than <img>

<div id=“photo” role=“img” aria-label=“One Photo”></div>

#photo {background-image: url(photo.png);

}

Page 33: High Performance Mobile Web

Reduce Reflow & Repaint

Page 34: High Performance Mobile Web

DOM Tree

Render Tree

Style Sheet

HTML

JavaScript

Flow

Paint

Page 35: High Performance Mobile Web

-webkit-tap-highlight-color:Overrides the highlight color shown when the

user taps a link or a JavaScript clickable element in Safari on iOS.

Page 36: High Performance Mobile Web

/* Avoid Repaint of JS Clickable Element*/

-webkit-tap-highlight-color: transparent

Page 37: High Performance Mobile Web

Use Touch Events

Page 38: High Performance Mobile Web

touchend Faster Than click

Page 39: High Performance Mobile Web

var tapEvent = ‘ontouchend’ in document ? ‘touchend’ : ‘click’;

node.delegate(tapEvent, …);

Page 40: High Performance Mobile Web

Hardware Acceleration

Page 41: High Performance Mobile Web

http://www.sencha.com/blog/understanding-hardware-acceleration-on-mobile-browsers/

Page 42: High Performance Mobile Web

/* Force 3D Acceleration */

-webkit-transform: translate3d(0,0,0);

-webkit-transform: tranlsateZ(0);

-webkit-transform: scale3d(1,1,1);

-webkit-transform: scale3dZ(1);

Page 43: High Performance Mobile Web

Hardware AccelerationConsumes Battery & Memory

Page 44: High Performance Mobile Web

AppCache For Full Screen

Page 45: High Performance Mobile Web

Ideally, Mobile Web Can Be Full Screen

Page 46: High Performance Mobile Web

$(window).on('load', function() { /mobile/i.test(navigator.userAgent) && !location.hash && setTimeout(function () { if (!win.pageYOffset) window.scrollTo(0, 1); }, 200);});

Page 47: High Performance Mobile Web

Address Bar is Hidden

ToolBar is Still There

Page 48: High Performance Mobile Web

<!-- enable full-screen mode --><meta name="apple-mobile-web-app-capable"

content="yes"/>

<!-- controls the appearance of the status bar in full-screen mode -->

<meta name="apple-mobile-web-app-status-bar-style" content="black"/>

Page 49: High Performance Mobile Web

Status Bar is Customized

ToolBar is Hidden

Page 50: High Performance Mobile Web

Till iOS5, Full Screen Web Launched From Home Screen Cannot Leverage Browser Cache

Page 51: High Performance Mobile Web

AppCache Helps Full Screen

<!doctype html><html manifest=“index.appcache”><head>…

CACHE MANIFESTx.htmlxxx.jsxxx.cssxxxxxx.png

Page 52: High Performance Mobile Web

Dawn of Mobile Web Performance

Page 53: High Performance Mobile Web

Thank You!

Page 54: High Performance Mobile Web

Find Me

@morgancheng

@程墨Morgan

http://www.facebook.com/morgan.chengmo