Pablo Villalba -

81
Mobile development

description

 

Transcript of Pablo Villalba -

Page 1: Pablo Villalba -

Mobile development

Page 2: Pablo Villalba -

@micho

Page 3: Pablo Villalba -

I code ruby and javascriptspecializing on user experience

Page 4: Pablo Villalba -

I founded Teambox

share tasks and files with your team

Page 5: Pablo Villalba -

This presentation will be online

I will tweet the link from @micho

Page 6: Pablo Villalba -

Mobile developmentMobile Development with HTML5 and Client-Side Javascript: Development Patterns, Backbone, APIs.

Writing cross-browser apps for multiple devices with a single code base and providing the best user experience.Optimizing resources for bandwith and better load times. Caching. Achieving local-fast apps.

Leveraging native look and feel and native features.

Page 7: Pablo Villalba -

Mobile developmentMobile Development with HTML5 and Client-Side Javascript: Development Patterns, Backbone, APIs.

Writing cross-browser apps for multiple devices with a single code base and providing the best user experience.Optimizing resources for bandwith and better load times. Caching. Achieving local-fast apps.

Leveraging native look and feel and native features.

Usable and fast

Page 8: Pablo Villalba -

1. Design for mobile

2. Client-side patterns

3. Load time performance

Page 9: Pablo Villalba -

Do you remember when...

The web was made of static content

Page 10: Pablo Villalba -

Then pages got more complicated

We processed server-side code

<?php ...

Page 11: Pablo Villalba -

And development changed, using

JS libraries and MVC frameworks

Page 12: Pablo Villalba -

Our tools have changed,but the platform

was always the PC

Page 13: Pablo Villalba -

Mobile is a brave new world

Page 14: Pablo Villalba -

Touch UI

App-stores

GPS, accelerometer, etc

The good

Page 15: Pablo Villalba -

Limited resources

Smaller displays

Apps need to be adapted for touch

The bad

Page 16: Pablo Villalba -

Unknown browser

Unknown device resolution

Difficulty supporting native features

The ugly

Page 17: Pablo Villalba -

Good Design & Speed

What makes for great user experience?

Page 18: Pablo Villalba -

1. Design for mobile

Page 19: Pablo Villalba -

What does Good Design

mean in mobile?

Page 20: Pablo Villalba -
Page 21: Pablo Villalba -

Design for fingertips

Page 22: Pablo Villalba -

Design for fingertips

Page 23: Pablo Villalba -

Design for smaller screens

Page 24: Pablo Villalba -

Design for smaller screens

Page 25: Pablo Villalba -

Navigation differs

Page 26: Pablo Villalba -
Page 27: Pablo Villalba -
Page 28: Pablo Villalba -
Page 29: Pablo Villalba -

Start with the essentialsand add extras if you can

Page 30: Pablo Villalba -

mobile

content

Page 31: Pablo Villalba -

mobile

tablet

content + navigation

Page 32: Pablo Villalba -

mobile

tablet

desktop

content + navigation + extras

Page 33: Pablo Villalba -

(i didn’t make that up)

the cool guys call itresponsive design

Page 34: Pablo Villalba -

prepare layout so your content can resize

use onResize events to adapt your content

Page 35: Pablo Villalba -

now for browsers

Page 36: Pablo Villalba -

mobile is mostly webkit

Page 37: Pablo Villalba -

modern JS and CSS

Page 38: Pablo Villalba -

but HTML5 support is notuniversal just yet

Page 39: Pablo Villalba -

modernizr.jsdetect native HTML5 support

in your device easily

Page 40: Pablo Villalba -

overflow: auto

scrolling in touch devices is stillprety quirky if you use scrollable divs

Page 41: Pablo Villalba -

dropdowns and hover

in touch devices there’s no hoverrevisit your UI to make sure everything works

Page 42: Pablo Villalba -

and then, there’s JS

Page 43: Pablo Villalba -

jQuery and others are still fine,but....

Page 44: Pablo Villalba -

if you are only targeting mobile,there are specific JS libraries

zepto.js

7 Kb (vs jQuery, which is 31 Kb)

targets only

Page 45: Pablo Villalba -

and some specific CSS frameworks

jQuery mobile

Adds powerful CSS conventions to create mobile UIs

Page 46: Pablo Villalba -

and one more thing!

PhoneGap, Appcelerator’s Titanium

These apps allow you to package your web app asa native application, so you may place it in App Storesor leverage platform specific features (like camera)

Page 47: Pablo Villalba -

PhoneGap, Appcelerator’s Titanium

These apps allow you to circumvent thecross-domain policy for web apps, so you can

perform AJAX requests to and from any domain

Page 48: Pablo Villalba -

2. Client-side patterns

Page 49: Pablo Villalba -

Web apps will work mostly fine,

but let’s discuss web apps

Page 50: Pablo Villalba -

When users access yoursite.com

you have two options

Page 51: Pablo Villalba -

a) Serve an responsive app that

adapts the content to mobile UI

with CSS and JS

Pros: Less code to maintain

Cons: You are probably sending too much content

Page 52: Pablo Villalba -

b) Serve a specific app for mobile

Pros: Specific and optimized contents

Cons: You need to maintain separate versions

Page 53: Pablo Villalba -

Detecting mobile browsers

You can do browser sniffing to detect the device

You can use special meta directives for mobile (zoom, icon)

You can use JS to detect dimensions of the viewport

Page 54: Pablo Villalba -

Sophisticated web apps are more data oriented

There’s a new generation of client-side frameworks

Page 55: Pablo Villalba -

Backbone.jsa “MVC” for the browser

Page 56: Pablo Villalba -

normally you wouldadd JS for every action

that’s hard to maintain

Page 57: Pablo Villalba -

normally you wouldask the DOM for data

since we use APIs, that seems redundant

Page 58: Pablo Villalba -

you used to handle clickswith AJAX to render quickly

it’s hard to structure views with AJAX

Page 59: Pablo Villalba -

Backbone.jsYour server sends JSON,

the browser builds the page locallywith Backbone and view templates

Page 60: Pablo Villalba -

Model, Collection

View

Controller (Router)

Page 61: Pablo Villalba -

Model, Collection

Holds JSON data and methods for it

E.g.: Tweet (model), timeline (collection)

{ user: {id: 2, name: “micho”}, tweet: “hai!” }

Page 62: Pablo Villalba -

Views

Linked to a model or collection

Creates HTML from the data andlistens for changes to re-render itself

view = new Views.Tweet({ model: tweet });

$(“#content”).append(view.render().el);

Page 63: Pablo Villalba -

Controllers

Routes pages to render actions

This way you can link to /#!/page and change the viewwithout navigating away. Faster!

http://site.com/#!/activities will render the Activities

Page 64: Pablo Villalba -

Example Twitter app

Model: User

Model: TweetView: My stats

View: Tweet

View: Timeline

View: New tweetCollection: Timeline

Page 65: Pablo Villalba -

Example Twitter app

My stats

5 tweetsTimeline

New tweet

TweetTweetTweet

Page 66: Pablo Villalba -

Example Twitter app

My stats

6 tweetsTimeline

New tweet

TweetTweetTweet

Posting a new tweetupdates the collection.

Views reflect the stateTweet

Page 67: Pablo Villalba -

How Backbone loads data

Bootstrap load the initial state

Navigating can get new data with AJAX,through your server’s API

You can use Websockets and Push

Page 68: Pablo Villalba -

Serving templates

Backbone uses view templates to display data.Your server needs to send these as a JS file.

“@{{user_name}} said: {{tweet}”

Page 69: Pablo Villalba -

Backbone is well suited for mobile

Minimal feature set

JS and data-centric

Built over jQuery and Underscore

Page 70: Pablo Villalba -

Other alternatives...

Spine & Spine Mobile

Sproutcore – more sophisticated

Sencha – adds UI elements too

Page 71: Pablo Villalba -

3. Load time performance

Page 72: Pablo Villalba -

speed matters

Page 73: Pablo Villalba -

slow gunners die

Page 74: Pablo Villalba -

Your app loads like this:

HTML page

CSS and images in parallel

JS: <scripts> block the page loadTemplates, if your app uses them

Page 75: Pablo Villalba -

Every ms matters!

HTML

CSS

JS

Cache aggressively, minimize DOM

Minify, use sprites, adopt conventions

Minify, use async loaders

Page 76: Pablo Villalba -

Page load experience

If you’re building JS apps, your HTML

should be minimal and let the JS populate it.

Add spinners and provide constant feedback to users.

Page 77: Pablo Villalba -

Asset caching

Serve assets with md5s of the contentand no-expire cache headers

application-76fbac76876.js

styles-7f2e1ac10bb.css

Page 78: Pablo Villalba -

HTML5‘s applicationCache

You can “remember” the last HTML you sawto make the page load experience extra fast!

Awesome for offline apps or faster page loading

Page 79: Pablo Villalba -

That’s the intro I wish I had readI hope it was useful for you

Page 80: Pablo Villalba -

We’ve been using all this to build

our collaboration platform

So go ahead and check it out!

Page 81: Pablo Villalba -

Thanks!

I’m @micho on Twitter