c o d e . t a l k s 
ON CONNECTION LOST 
Das Leben einer Offline Web-Applikation
JOHANNES 
ŁUKASZ 
[wukaʃ] 
[joˈhanəs]
OFFLINE ??!
WHAT IS 
OFFLINE ?
STUPID 
CLIENT
MORE LOGIC 
CLIENT-SIDE
INDEPENDENT 
CLIENT
By integrating offline 
capabilities, you will end up 
with resilient architecture of 
the system as a whole (both 
client and server)
DIFFERENT 
STEPS 
https://www.flickr.com/photos/bootbearwdc/611056260
CLIENT AVAILABLE 
1 OFFLINE
2 DATA AVAILABLE 
OFFLINE 1 
CLIENT AVAILABLE 
OFFLINE
3 DATA CHANGES 
OFFLINE 
2 DATA AVAILABLE 
OFFLINE 
CLIENT AVAILABLE 
OFFLINE 
1
https://www.flickr.com/photos/soeren_nb/3444697357
APPLICATION 
CACHE
INDEX.HTML 
1 <!doctype html> 
2 <html ... manifest="appcache.manifest"> 
. <!-- (...) --> 
54 </html>
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
INITIAL DOWNLOAD 
CHECKING 
DOWNLOADING 
PROGRESS 
CACHED
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
NO INTERNET 
LOADED 
CHECKING 
ERROR
NOTHING CHANGED 
LOADED 
CHECKING 
NO UPDATE
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
NEW VERSION 
LOADED 
CHECKING 
DOWNLOADING 
PROGRESS 
UPDATE READY
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
ADDITIONAL CACHE
YES YES YES IE 10 
http://caniuse.com/#search=appcache
DATA 
https://www.flickr.com/photos/bootbearwdc/611056260
WEB STORAGE 
LocalStorage 
SessionStorage 
IndexedDB 
Web SQL 
File Api 
Easy to use key/value store 
Synchronous API 
Limit: 5MB 
Limit: 2GB 
Complex asynchronous API 
Good performance -> indices 
Asynchronous API 
Quota Mgmt API / unlimited
INDEXED DB 
https://www.flickr.com/photos/16712259@N04/4467481701
THE API 
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 
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 = // ...
YES YES 7.1 IE 10 
http://caniuse.com/#search=indexeddb
BINARY DATA 
https://www.flickr.com/photos/wales_designer/346469146
ACCESSING FILE SYSTEM 
16 $window.webkitStorageInfo.requestQuota( 
$window.PERSISTENT, 
sizeInMb * 1024 * 1024, 
function () { 
$window.webkitRequestFileSystem( 
$window.PERSISTENT, 
sizeInMb * 1024 * 1024, 
successFct, errorFct); 
}, errorFct);
! 
WRITE AND USE 
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 
filesystem:http://yourdomain/persistent/filename
YES YES 6.1 IE 10 
http://caniuse.com/#search=fileapi
SYNC 
https://www.flickr.com/photos/trainor/1229138273
COMMANDS
COMMANDS
COMMANDS
COMMANDS
QUEUE 
queued 
in sync 
in conflict 
https://www.flickr.com/photos/richardsummers/269503769
SYNCING
SYNCING
SYNCING
SYNCING
SYNCING
SYNCING
SYNCING
3 DATA CHANGES 
OFFLINE 
2 DATA AVAILABLE 
OFFLINE 
CLIENT AVAILABLE 
OFFLINE 
1
LESSONS LEARNED
DISTRIBUTED DB
RACE CONDITIONS 
https://www.flickr.com/photos/botheredbybees/1849920478
CHALLENGE 
REQUIREMENTS
DANKE

On connection lost