How to build mobile apps that work offline?
The code examples are available on github :
https://github.com/creynaud/notes-iphone-app
https://github.com/creynaud/notes-server
A blog post on the same subject: https://www.clairereynaud.net/blog/adding-offline-mode-to-your-mobile-app/
12. Mobile networks are different
Latency is high
Speed is very inconsistent, which is bad in terms
of UX
Watch the "Faster Websites: Crash Course on
Frontend Performance (Part 1/2)" talk from
Devoxx 2012
13. Your app in the wild
Try your app with the Network Conditioner
21. You need a higher level cache
You may want to do offline search requests
You may want to do offline edition
You can use CoreData on top of SQLite, or
another storage mechanism.
Depending on your needs, storing the raw
JSON document in a key/value store may be
enough.
22. What to keep from HTTP caching
though?
For example, I don't want to re-download a given
version of a JSON document if I already have it in the
HTTP cache.
This is possible with HTTP caching headers:
Cache-Control
Etag and If-None-Match
or Last-Modified and If-Modified-Since
29. Creating notes while offline
1. Store (e.g in SQLite) the JSON document that
needs to be posted
2. Try to post the JSON document to the server in
the background
3. Mark the JSON document has successfully
posted only if POST succeeds
4. In case of failure, retry to post the
JSON document during next sync with the server
35. What about Android apps?
More or less the same:
Put a uuid and a revision on all your JSON
documents
Offline read: store your JSON Documents in
SQLite
Offline create: POST to the server in the
background and retry if needed
Offline update: handle conflicts
Try to leverage HTTP caching
39. You can use whatever you want
This is what I use, but it's really up to you
40. Let's see how it works with Django
REST framework
Put a uuid and a revision on your Note objects
Reject PUT or DELETE request if it does not
provide a revision (400 Bad request)
Reject PUT or DELETE request if the revision is
not the current one (409 Conflict)
Everything else comes out of the box!
https://github.com/creynaud/notes-server
https://awesomenotes.herokuapp.com/api/
41. Summary
Put a uuid and a revision on all your JSON
documents
Offline read: store your JSON Documents in
SQLite
Offline create: POST to the server in the
background and retry if needed
Offline update: handle conflicts
Try to leverage HTTP caching (Cache-Control,
Etag and If-None-Match headers)