Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

66
Turbocharge your mobile web apps Jan Jongboom @janjongboom

description

Offline is awesome. Overview of packaged apps, appcache, service workers, caching AJAX requests, etc.

Transcript of Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Page 1: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Turbocharge your mobile web apps

Jan Jongboom@janjongboom

Page 2: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Speed is awesome!

Page 3: Develop:BBC 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: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

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

Page 5: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

@janjongboom

Page 6: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline
Page 7: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

37%

Page 8: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline
Page 9: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Part 0: Core concepts

Page 10: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

1. The shell2. App content

Page 11: Develop:BBC 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: Develop:BBC 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: Develop:BBC 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: Develop:BBC 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: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Part I: The shell

Page 16: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Packaging

Page 17: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Packaging

Page 18: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Publishing on the web = awesome

Page 19: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

AppCache: a more web’y approach

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

example.appcache

Serve as text/cache-manifest

Page 25: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

example.appcache

Serve as text/cache-manifest

Page 26: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

example.appcache

Serve as text/cache-manifest

Page 27: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

How AppCache works

Page 28: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline
Page 29: Develop:BBC 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• Develop with appcache enabled

(tip: set wrong MIME type in dev)

Page 31: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Performance metrics

1500 msEmpty cache

Page 32: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Performance metrics

820 msSubsequent reload

Page 33: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Performance metrics

320 msReload with appcache

Page 34: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

250% speed bumpNot just for of!ine

Page 35: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Sounds perfect, right?

Page 36: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

1. It breaks the web

Page 37: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

2. You’re not in control about caching

Page 38: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

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

Page 39: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

4. Responsive design is hard

Page 40: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Give developers "ne-grained control about caching, without

breaking the web

Page 41: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

ServiceWorkersFirst request

Grabbing jan.com/index.html

Page 42: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

ServiceWorkersFirst request

Grabbing jan.com/index.html

For foo/* please consult me!

Page 43: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

ServiceWorkers2nd request

I need foo/blah

Page 44: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

ServiceWorkers2nd request

I need foo/blah

Page 45: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

ServiceWorkers2nd request

I need foo/blah

200 OK!

Page 46: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Example: registering

Page 47: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Example: registering

Page 48: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Example: registering

Page 49: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Example: use cache

Page 50: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Example: use cache

Page 51: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Example: use cache

Page 52: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Ongoing work in Gecko / Blink

Page 53: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

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

Page 54: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Part II: App content

Page 55: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

A simple AJAX request

Page 56: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

A simple AJAX request

Page 57: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

A simple AJAX request

Page 58: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Naive caching with localStorage

Page 59: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Naive caching with localStorage

Page 60: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Naive caching with localStorage

Page 61: Develop:BBC 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 63: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Part IV: Lessons learned

Page 64: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Lessons learned

Page 65: Develop:BBC 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 66: Develop:BBC 2013 - Turbocharge your mobile web apps by using offline

Thank you!

slideshare.net/janjongboom