Slide 1

Slide 1 text

Offline rules Making your eb app ork offline and be more aesome online ndre Betts (@triblondon) Director, FT Labs (@ftlabs)

Slide 2

Slide 2 text

1880 1900 1920 1940 1960 1980 2000 2020 e’ve been doing this for a hile.

Slide 3

Slide 3 text

orks offline Portable Long battery life Can be read in bright sunlight Cheap Ubiquity Bookmarking Sharing Features (nesprint) Fast start up Clipping/saving Can be read in the dark Updates in real time Electronic delivery Search Personalisation Deep linking

Slide 4

Slide 4 text

e need to care about supporting existing features as much as getting ne ones.

Slide 5

Slide 5 text

orks offline Portable Long battery life Can be read in bright sunlight Cheap Ubiquity Bookmarking Sharing Features (HTML5?) Fast start up Clipping/saving Can be read in the dark Updates in real time Electronic delivery Search Personalisation Deep linking

Slide 6

Slide 6 text

The FT eb app The FT eb app provides a touch optimised user experience ithout native code.

Slide 7

Slide 7 text

…and the Economist app n HTML5 ebsite rapped in BlackBerry eborks for app orld distribution on the PlayBook.

Slide 8

Slide 8 text

Offline vs dependency management Offline vs responsive images Offline vs media queries Offline vs analytics Offline vs login state

Slide 9

Slide 9 text

Offline makes everything harder.

Slide 10

Slide 10 text

Client side storage options Meet the family from hell.

Slide 11

Slide 11 text

ppCache Teen localStorage Dad IndexedDB Mum Cookies Grandad

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

appCache indexedDB

Slide 14

Slide 14 text

Speed: read/rite cycles 242   296   175   259   6873   29897   1 10 100 1000 10000 100000 IDB Large IDB Small ebSQL Large ebSQL Small localStor Large localStor Small Operations per second (more is better) h,p://jsperf.com/indexeddb-­‐vs-­‐localstorage/13  

Slide 15

Slide 15 text

Bootstrapping Start small and enhance

Slide 16

Slide 16 text

CONTENT   adver   Ising   adverIsing   adverIsing   twaddle   crap   nonsense   tomfoolery   tripe   baloney   garbage   poppycock   trash   rubbish   filler   irrelevance   faff   hidden   unseen   ferreted   concealed   invisible   buried   latent   sequestered   shrouded   unrevealed   withheld  

Slide 17

Slide 17 text

hy Bootstrap? •  Keep content clean •  Start ‘enhanced experience’ on any URL – Need front-end router / front controller •  Handle errors •  Run only hat e need •  Mollify attention seeking app cache

Slide 18

Slide 18 text

Main content Basic CSS / fonts Boot and error handling code JS modules CSS modules HTML fragments dditional content Initial pageload appCache/Netork Modules and dependencies Local storage / appCache / netork uthentication tokens Cookies Extra content and prefetching ebSQL / IndexedDB / netork uthentication token

Slide 19

Slide 19 text

Taming the appCache Grump grump grump grump grump...

Slide 20

Slide 20 text

CACHE MANIFEST # 14120120420 / /favicon.ico /lib/fonts/ofsnmd__.ttf /lib/imgs/sprite.png FALLBACK: /issues /fb/issues /api /fb/api NETWORK: * Manifest version Explicit caching llo stuff not in appcache Offline controllers

Slide 21

Slide 21 text

ny page ith manifest attribute ill get cached, like it or not. ny cached page ill be used in preference to fetching a fresh copy, even hen online.

Slide 22

Slide 22 text

   

Slide 23

Slide 23 text

Only cache one ‘master’ URL: ...

Slide 24

Slide 24 text

Internet Explorer ill not populate an appCache unless the manifest is cacheable. Firefox on’t store any resource if it’s served ith no-store, even if explicitly listed in the manifest.

Slide 25

Slide 25 text

Cache-control: max-age=1, private; Prevent proxy caching

Slide 26

Slide 26 text

hen the manifest is updated, every entry in it is redonloaded

Slide 27

Slide 27 text

CACHE MANIFEST # 14120120420 /js/mymodule1.js?v=1.15 /js/mymodule2.js?v=1.18 /js/mymodule3.js?v=1.1 /js/mymodule4.js?v=1.18 /js/mymodule5.js?v=1.19 FALLBACK: /issues /fb/issues?v=2.34 /api /fb/api?v=2.34 NETWORK: * Manifest version Far future cached resources

Slide 28

Slide 28 text

ppCache HTTP Cache Server Updated manifest Donload just one

Slide 29

Slide 29 text

On slo netorks a request must time out before the fallback is used.

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

hat e put in app cache YES: •  Fonts •  Splash image •  pp icon •  Entry page •  Fallback bootstrap NO: •  CSS •  HTML •  JavaScript Local Storage

Slide 33

Slide 33 text

Storage optimisation ll storage technologies are limited by tiny quotas. e need to learn to live ith less.

Slide 34

Slide 34 text

ebSQL () / IndexedDB (i) ppcache localStorage Cookies iOS (5.1) : 5MB / 50MB 10MB 5MB 4KB total Up to 50 per domain ndroid (4) ? Unlimited 5MB Safari (5.2) : 5MB / Unlimited Unlimited 5MB Chrome (18) : Unlimited 5MB 5MB IE (10) i: 500MB 50MB 10MB Opera (11) : 5MB / Unlimited 50MB / Unlimited 5MB / Unlimited Firefox (11) i: 50MB / Unlimited Unlimited 10MB Storage limits Two  figures  separated  by  /  indicate  limit  with  and  without  user  consent  prompt,  which  appears  automaIcally  when  you  try  to   store  more  than  the  lower  limit.    The  user  may  not  consent  to  more  than  the  upper  limit.  

Slide 35

Slide 35 text

UTF-16 in JavaScript •  Provides great compatibility but halves precious quota! •  Can make compromises on compatibility to get more storage efficiency 00   48   00   45   00   4C   00   4C   00   4F   00   20   00   57   00   4F   00   52   00   4C   00   44   H   E   L   L   O   W   O   R   L   D  

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

Squeezing your bits Text   S   i   m   p   l   e   Decimal   83   105   109   112   108   101   As  binary   01010011   01101001   01101101   01110000   01101100   01100101   Shi[ed   01010011  01101001   01101101  01110000   01101100  01100101   As  hex   53  69   6D  70   6C  65   UTF-­‐16   卩   浰   汥  

Slide 38

Slide 38 text

SCII packed into UTF-16! Simple = 卩浰汥 6 chars 3 chars

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

Connection state Taking online and offline events at face value

Slide 41

Slide 41 text

Q: If the value of indo.navigator.onLine is true, hat does that mean? : The device might be online.

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

Tell hat you kno, not hat you assume.

Slide 44

Slide 44 text

Donloading! Not sure. Still trying... Bah. e give up.

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

“Don’t build native apps, build eb apps” -­‐  Tim  Berners-­‐Lee  

Slide 47

Slide 47 text

Thanks andre@labs.ft.com @triblondon, @FTLabs Do you ant to build this stuff? Join in. [email protected]