velocityconf eu 2013 - turbocharge your mobile web apps by using offline

74
Turbocharge your mobile web apps Jan Jongboom VelocityConf EU 2013

Upload: jan-jongboom

Post on 08-May-2015

1.064 views

Category:

Technology


2 download

DESCRIPTION

Presentation I gave on November 14, 2013 during VelocityConf EU 2013. Offline is awesome. Overview of packaged apps, appcache, service workers, caching AJAX requests, two-way data syncing, etc.

TRANSCRIPT

Page 1: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Turbocharge your mobile web apps

Jan JongboomVelocityConf EU 2013

Page 2: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Fast websites are awesome!

Page 3: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

blah, blah, blah, caching, blah, expiration headers, blah, blah,

image maps, blah, blah, combining css, blah, blah, minifying, blah, blah,

blah

Page 4: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

New tricks!Didn’t even exist when “High Performance Websites” came out

Page 5: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

@janjongboom

Page 6: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline
Page 7: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

37%

Page 8: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline
Page 9: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Part 0: Core concepts

Page 10: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

1. The shell2. App content

Page 11: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

The shell

• All assets• Distribution through:

• App store• Publish on web server

• Changes are costly

Page 12: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

The shell

• All assets• Distribution through:

• App store• Publish on web server

• Changes are costly

Page 13: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

App content

• Everything your app serves up• Pushed down from server• Highly volatile• Changes are cheap

Page 14: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

App content

• Everything your app serves up• Pushed down from server• Highly volatile• Changes are cheap

Page 15: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Part I: The shell

Page 16: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Packaging

Page 17: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Packaging

Page 18: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Publishing on the web = awesome

Page 19: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

AppCache: a more web’y approach

Page 20: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline
Page 21: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline
Page 22: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline
Page 23: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline
Page 24: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

example.appcache

Serve as text/cache-manifest

Page 25: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

example.appcache

Serve as text/cache-manifest

Page 26: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

example.appcache

Serve as text/cache-manifest

Page 27: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

How AppCache works

Page 28: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline
Page 29: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Shit you will do wrong

• Setting wrong MIME type• Have one !le 404• Not realizing user will always see old

version !rst• Expiration headers on appcache• Develop with appcache enabled

(tip: set wrong MIME type in dev)

Page 31: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Performance metrics

1500 msEmpty cache

Page 32: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Performance metrics

820 msSubsequent reload

Page 33: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Performance metrics

320 msReload with appcache

Page 34: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

250% speed bumpNot just for of!ine

Page 35: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Sounds perfect, right?

Page 36: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

1. It breaks the web

Page 37: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

2. You’re not in control about caching

Page 38: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

3. You’re not in control about of!ine behavior

Page 39: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

4. Responsive design is hard

Page 40: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Give developers "ne-grained control about caching, without

breaking the web

Page 41: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

ServiceWorkersFirst request

Grabbing jan.com/index.html

Page 42: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

ServiceWorkersFirst request

Grabbing jan.com/index.html

For foo/* please consult me!

Page 43: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

ServiceWorkers2nd request

I need foo/blah

Page 44: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

ServiceWorkers2nd request

I need foo/blah

Page 45: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

ServiceWorkers2nd request

I need foo/blah

200 OK!

Page 46: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Example: registering

Page 47: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Example: registering

Page 48: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Example: registering

Page 49: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Example: use cache

Page 50: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Example: use cache

Page 51: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Example: use cache

Page 52: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Ongoing work in Gecko / Blink

Page 53: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Spec & playing aroundhttps://github.com/slightlyoff/ServiceWorker

Page 54: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Part II: App content

Page 55: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

A simple AJAX request

Page 56: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

A simple AJAX request

Page 57: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

A simple AJAX request

Page 58: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Naive caching with localStorage

Page 59: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Naive caching with localStorage

Page 60: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Naive caching with localStorage

Page 61: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline
Page 62: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline
Page 63: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Making it less naive

• Use indexedDB: http://nparashuram.com/IndexedDBShim/• Wrap around current AJAX lib• Expiration dates• Of"ine -> ignore expiration date

Page 65: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Part III: Keeping in sync

Page 66: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Two way syncing is hard!

Page 67: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

It all depends

• Operational transform library. F.e. ShareJS• Objects? F.e. https://github.com/codeparty/racer• Real deal? PouchDB

Page 68: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Why I like PouchDB

1. It stores data locally, syncs when there is connection2. Can do syncing client->server, server->client, or both ways3. Con"ict resolution can be easily programmed out.

Page 69: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Why I like PouchDB

1. It stores data locally, syncs when there is connection2. Can do syncing client->server, server->client, or both ways3. Con"ict resolution can be easily programmed out.

4. Dale Harvey is gonna buy me beer when I show him this slide

Page 70: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Part III: Lessons learned

Page 71: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Lessons learned

Page 72: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Lessons learned

• Of"ine is awesome, speed is awesome!• Cache shell: packaging, appcache or ServiceWorkers• Cache content: localStorage, indexedDB, write cache logic that

suits you• Data syncing: hard, take something off the shelf

Page 73: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Thank you!

slideshare.net/janjongboom

Page 74: VelocityConf EU 2013 - Turbocharge your mobile web apps by using offline

Questions?Wanna chat about Firefox OS; Of!ine; Mobile landscape; What beer you should buy Dutch

speakers; etc.?

Of"ce hours with me at 14:45 (Table 3)

slideshare.net/janjongboom