on connection lost

58
code.talks ON CONNECTION LOST Das Leben einer Oine Web-Applikation

Upload: lukasz-plotnicki

Post on 30-Jun-2015

401 views

Category:

Technology


3 download

DESCRIPTION

Slides from the code.talks 2014 talk about realising offline web-applications.

TRANSCRIPT

Page 1: On connection lost

c o d e . t a l k s

ON CONNECTION LOSTDas Leben einer Offline Web-Applikation

Page 2: On connection lost

JOHANNESŁUKASZ

[wukaʃ]

[joˈhanəs]

Page 3: On connection lost

OFFLINE ??!

Page 4: On connection lost
Page 5: On connection lost

WHAT ISOFFLINE ?

Page 6: On connection lost

STUPIDCLIENT

Page 7: On connection lost

MORE LOGICCLIENT-SIDE

Page 8: On connection lost

INDEPENDENTCLIENT

Page 9: On connection lost

By integrating offline capabilities, you will end up

with resilient architecture of the system as a whole (both

client and server)

Page 10: On connection lost

DIFFERENT STEPS

https://www.flickr.com/photos/bootbearwdc/611056260

Page 11: On connection lost

CLIENT AVAILABLE OFFLINE1

Page 12: On connection lost

CLIENT AVAILABLE OFFLINE

2 DATA AVAILABLE OFFLINE

1

Page 13: On connection lost

CLIENT AVAILABLE OFFLINE

2 DATA AVAILABLE OFFLINE

3 DATA CHANGES OFFLINE

1

Page 14: On connection lost

https://www.flickr.com/photos/soeren_nb/3444697357

Page 15: On connection lost

APPLICATIONCACHE

Page 16: On connection lost

INDEX.HTML

1 <!doctype html> 2 <html ... manifest="appcache.manifest"> . <!-- (...) --> 54 </html>

Page 17: On connection lost

APPCACHE.MANIFEST 1 CACHE MANIFEST 2 # rev 1 - 2014-10-03T13:50:18.799Z 3 4 CACHE: 5 404.html 6 favicon.ico 7 scripts/scripts.js # (...) 111 112 NETWORK: 113 * 114 115 FALLBACK: 116 / /offline.html

Page 18: On connection lost

INITIAL DOWNLOAD

CHECKING DOWNLOADING PROGRESS CACHED

Page 19: On connection lost

APPCACHE.MANIFEST 1 CACHE MANIFEST 2 # rev 1 - 2014-10-03T13:50:18.799Z 3 4 CACHE: 5 404.html 6 favicon.ico 7 scripts/scripts.js # (...) 111 112 NETWORK: 113 * 114 115 FALLBACK: 116 / /offline.html

Page 20: On connection lost

NO INTERNET

LOADED CHECKING ERROR

Page 21: On connection lost

NOTHING CHANGED

LOADED CHECKING NO UPDATE

Page 22: On connection lost

APPCACHE.MANIFEST 1 CACHE MANIFEST 2 # rev 1 - 2014-10-03T13:50:18.799Z 3 4 CACHE: 5 404.html 6 favicon.ico 7 scripts/scripts.js # (...) 111 112 NETWORK: 113 * 114 115 FALLBACK: 116 / /offline.html

Page 23: On connection lost

NEW VERSION

LOADED CHECKING DOWNLOADING PROGRESS UPDATE READY

Page 24: On connection lost

APPCACHE.MANIFEST 1 CACHE MANIFEST 2 # rev 1 - 2014-10-03T13:50:18.799Z 3 4 CACHE: 5 404.html 6 favicon.ico 7 scripts/scripts.js # (...) 111 112 NETWORK: 113 * 114 115 FALLBACK: 116 / /offline.html

Page 25: On connection lost

ADDITIONAL CACHE

Page 26: On connection lost
Page 27: On connection lost

IE 10YESYES YEShttp://caniuse.com/#search=appcache

Page 28: On connection lost

DATA

https://www.flickr.com/photos/bootbearwdc/611056260

Page 29: On connection lost

WEB STORAGE

File Api

LocalStorageSessionStorage

IndexedDBWeb SQL

Limit: 5MB

Easy to use key/value store Synchronous API

Limit: 2GB Complex asynchronous API Good performance -> indices

Quota Mgmt API / unlimitedAsynchronous API

Page 30: On connection lost

INDEXED DBhttps://www.flickr.com/photos/16712259@N04/4467481701

Page 31: On connection lost

169 var request = indexedDB.open('db_name', '1'); !

13 var trans = database.transaction(['name'], 'readwrite'); 14 var store = trans.objectStore(collection); 16 var putRequest = store.put(object, key); 18 putRequest.onsuccess = // ... !

31 var trans = database.transaction(['name'], 'readonly'); 34 var getRequest = store.get(key); !

59 var index = store.index(indexName); 60 var cursorRequest = index.openCursor(); 63 cursorRequest.onsuccess = // ...

THE API

Page 32: On connection lost

169 var request = indexedDB.open('db_name', '1'); !

13 var trans = database.transaction(['name'], 'readwrite'); 14 var store = trans.objectStore(collection); 16 var putRequest = store.put(object, key); 18 putRequest.onsuccess = // ... !

31 var trans = database.transaction(['name'], 'readonly'); 34 var getRequest = store.get(key); !

59 var index = store.index(indexName); 60 var cursorRequest = index.openCursor(); 63 cursorRequest.onsuccess = // ...

THE API

Page 33: On connection lost

IE 107.1YES YEShttp://caniuse.com/#search=indexeddb

Page 34: On connection lost

BINARY DATAhttps://www.flickr.com/photos/wales_designer/346469146

Page 35: On connection lost

16 $window.webkitStorageInfo.requestQuota( $window.PERSISTENT, sizeInMb * 1024 * 1024, function () { $window.webkitRequestFileSystem( $window.PERSISTENT, sizeInMb * 1024 * 1024, successFct, errorFct); }, errorFct);

ACCESSING FILE SYSTEM

Page 36: On connection lost

!

35 fileSystem.root.getFile(fileName, {create: true}, function (fileEntry) { 37 fileEntry.createWriter(function (fileWriter) { 39 fileWriter.onwriteend = // ... 43 fileWriter.onerror = // ... 45 fileWriter.write(blob); 47 }, errorFct); 49 }, errorFct); 50 });

WRITE AND USE

Page 37: On connection lost

WRITE AND USE

filesystem:http://yourdomain/persistent/filename

Page 38: On connection lost

IE 106.1YES YEShttp://caniuse.com/#search=fileapi

Page 39: On connection lost

SYNChttps://www.flickr.com/photos/trainor/1229138273

Page 40: On connection lost

COMMANDS

Page 41: On connection lost

COMMANDS

Page 42: On connection lost

COMMANDS

Page 43: On connection lost

COMMANDS

Page 44: On connection lost

QUEUE

queued

in sync

in conflict

https://www.flickr.com/photos/richardsummers/269503769

Page 45: On connection lost

SYNCING

Page 46: On connection lost

SYNCING

Page 47: On connection lost

SYNCING

Page 48: On connection lost

SYNCING

Page 49: On connection lost

SYNCING

Page 50: On connection lost

SYNCING

Page 51: On connection lost

SYNCING

Page 52: On connection lost

CLIENT AVAILABLE OFFLINE

2 DATA AVAILABLE OFFLINE

3 DATA CHANGES OFFLINE

1

Page 53: On connection lost

LESSONS LEARNED

Page 54: On connection lost
Page 55: On connection lost

DISTRIBUTED DB

Page 56: On connection lost

RACE CONDITIONS

https://www.flickr.com/photos/botheredbybees/1849920478

Page 57: On connection lost

CHALLENGE REQUIREMENTS

Page 58: On connection lost

DANKE