Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

37
Building mobile web app Web Unleashed that don’t suck 2014-09-18 Frédéric Harper Sr. Technical Evangelist @ Mozilla @fharper | outofcomfortzone.net Creative Commons: https://ic.kr/p/dSUCBT

description

Mobility is everywhere. It’s even more important to think about smaller devices like smartphones when building application or game using web technology. Everybody wants to have a mobile application, but it's not sufficient: you need to create an awesome experience for your users, your customers. You need to be future proof, and think about different markets as users needs: you never know when your application will be the next Flappy Bird. This presentation is about concrete tips, tricks and guidelines for web developers using HTML, CSS, and JavaScript based on experience that will help you make a success of your next exciting mobile application or game idea.

Transcript of Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Page 1: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Building mobile web app

Web Unleashed

that don’t suck

2014-09-18

Frédéric Harper

Sr. Technical Evangelist @ Mozilla

@fharper | outofcomfortzone.net

Crea

tive

Com

mon

s: h

ttps

://fl

ic.k

r/p/

dSUC

BT

Page 2: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Creative Commons: https://flic.kr/p/2NbHtk

Page 3: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Crea

tive

Com

mon

s: h

ttps

://fl

ic.k

r/p/

7DSM

oB

Page 4: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Crea

tive

Com

mon

s: h

ttps

://fl

ic.k

r/p/

67Sg

Pg

Page 5: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Crea

tive

Com

mon

s: h

ttps

://fl

ic.k

r/p/

HgpX

C

Page 6: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Crea

tive

Com

mon

s: h

ttps

://fl

ic.k

r/p/

GbXa

j

Page 7: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

38 billion devices connected in 2020 ABI Research - 2013-05-09 - http://j.mp/38billion

Page 8: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Think differently

Page 9: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

The 3 motivations

1.  I’m microtasking

2.  I’m local

3.  I’m bored

Page 10: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Creative Commons: http://xkcd.com/773/

Page 11: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Mobile First

Creative Commons: https://flic.kr/p/dydMTQ

Page 12: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Responsive Web Design

Crea

tive

Com

mon

s: h

ttps

://fl

ic.k

r/p/

ctUn

bb

Page 13: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Reponsive Web Design

1.  A flexible, grid-based layout,

2.  Flexible images and media,

3.  Media queries.

Page 14: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

DEM

O

Page 15: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Offline mode

1.  Application cache

2.  localStorage

3.  IndexedDB

4.  Native Offline Support (ex.: package app on Firefox OX)

Page 16: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

UI & UX are important

Page 17: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Creative Commons: http://j.mp/1qKFfXq

Page 18: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Creative Commons: https://flic.kr/p/9engqG

Take off

Land

Page 19: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Creative Commons: http://j.mp/1qKFfXq

Page 20: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Creative Commons with permission from Parachute Desing: http://j.mp/1m8fgcH

The comfort zone

Page 21: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Fitt’s law

T = a + b × log2 (1 + D / W)

T: Average time taken to complete the movement a: Start/stop time of the device b: Inherent speed of the device D: Distance from the starting point to target center W: Width of target, measured along axis of motion

Page 22: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Fitt’s law, translated

The bigger and closer a target is, the easier it is to hit.

Page 23: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Optimize (when it make sense)

Page 24: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

JavaScript Google Closure is my preferred one •  Hoisting (joining variables declarations) •  Removing unreachable code •  Obfuscate your code •  Renaming variables (shortening) •  Remove unnecessary spaces/code •  Reduce files size https://github.com/google/closure-compiler http://closure-compiler.appspot.com/home

Page 25: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Minimize or speed up HTTP requests

•  Avoid or minimize 3xx redirections

•  GZIP encoding (htaccess, web.config)

•  Image sprites when it make sense

•  CDN (Content Distribution Network)

•  HTTP Cache Headers (Apache) or HTTP Expires Response Header (IIS)

Page 26: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Images

•  Use Native Image Resolution (original width, height)

•  Select the right image format (PNG, JPEG…)

•  Use image preview for videos

•  Compress your images

Page 27: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Be Flintheart Glomgold

ImageOptim (OS X) - https://imageoptim.com/ Trimage (Linux) - http://trimage.org/ PNGGauntlet (Windows) - http://pnggauntlet.com/

Shrink your images without losing quality

Page 28: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Be aware of the rendering

Solid black texture sized 1920x1080

Once compressed = ~5kb PNG

Decompressed to memory = up to 8mb

(1920 x 1080 x 4 bytes per pixels [rgba]) = 8294400 bytes

Page 29: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Small tips & tricks

•  Avoid plugins usage

•  Load JavaScript files at the end of the page

•  Asynchronously load scripts (async) when it’s possible

•  JSON is faster than XML

•  You don’t always need a framework or library

Page 30: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Miscellaneous micro-optimization

•  CSS for large bck images (DIV, CSS background under canvas)

•  Multiple canvases for layers

•  Don’t scale images in drawImage (cache in offscreen canvas)

•  Use WebGL* instead of Context 2D (free up CPU for GPU)

•  Avoid creating new object when it’s possible

Page 31: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

In the end…

Page 32: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Google Developers PageSpeed Insights https://developers.google.com/speed/pagespeed/insights/

Page 33: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

JsPerf is your friend

http

://j

sper

f.com

/bro

wse

Page 34: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Firefox Developer Tools

Page 35: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Try on low-end devices Firefox OS Flame http://j.mp/1pd7p8g ZTE Open http://j.mp/1tPUIYN

Page 36: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

The philosophy behind great apps…

1.  Don’t make us think about the interface

2.  Deal with complex tasks for us (insulate us from that complexity)

3.  Make accomplishing our goals easier

4.  Help users be awesome in the moment!

Page 37: Building Web Mobile App that don’t suck - FITC Web Unleashed - 2014-09-18

Frédéric Harper

[email protected]

@fharper

http://hacks.mozilla.org

http://outofcomfortzone.net