Showing posts with label HTML5 iPhone JavaScript WebApps. Show all posts
Showing posts with label HTML5 iPhone JavaScript WebApps. Show all posts

2009-11-23

Storing Persistent Data in Hybrid iPhone Webapps

I'm in the process of adding some persistence to a hybrid iPhone webapp. It looks like I'll be using the HTML5 Web Storage capability. I googled around and didn't find any comparisons of the alternatives or suggested best practices. Apple has a document called Safari Client-Side Storage and Offline Applications, which covers Key-Value storage and the JavaScript Database -- but makes no mention of hybrid applications.

It seems there are four possible options:
  1. Web Database
  2. Key-value storage
  3. Cookies
  4. Use a JavaScript to Cocoa bridge to access native persistence
I've given a little thought to the advantages and disadvantages of each (enough to decide to give HTML 5 Web storage a try.)  I'll update this document if I get any good feedback.


Web Database

Advantages
  • Can be used in hybrid, online and offline webapps.
  • Supported in iPhone OS 2.0 and later.
  • SQL is familiar and powerful for those who know it and need it.
Disadvantages
  • Use of SQL is overkill for simple persistence
Key-value Storage

Advantages
  • Simple conceptual model than SQL
  • Has both "session"and  "local"  modes
Disadvantages
  • Only supported in iPhone 3.0 and later (although Apple isn't very clear on this)
Cookies

Advantages
  • Tried and true web technology
Disadvantages
  • Either not supported in Hybrid mode or requires extra Cocoa code to support.  (Does anybody have a definitive answer, details, or an example?)
  • Extra data is transmitted to the server on each request
  • Others?
Custom JavaScript to Cocoa Bridge Option

Advantages
  • You can use any iPhone native mechanism for persistence
Disadvantages
  • Requires custom Cocoa code
  • JavaScript to Cocoa bridge options are fairly clunky
  • Will not work for pure online/offline webapp