Safely storing data in a HTML5 iOS application - are localStorage / WebSQL / IndexedDB appropriate?
Asked Answered
O

2

14

I'm writing a HTML5 application that I want to release on the iOS app store. Either using PhoneGap or wrapped in a UIWebView control.

I'm a bit confused about what options I have in terms of storing data for my application.

Are using localStorage, WebSQL or IndexedDB technologies appropriate for storing application data in this type of application? I will be storing JSON and XML data.

Keep in mind, if the user inadvertently deletes this data then they will have lost their work, which obviously I don't want to happen.

I understand that the only real way to alleviate this risk is to sync the data to the "cloud" or other online system - I can do that in a future release, but not right now. Initially I just want to store the data locally if that is a reasonable stable way to do things.

From what I understand, when clearing the cookies the browser will also clear any localStorage data. So that rules that out, as I can see users doing that by accident.

WebSQL looks pretty good - the user can't inadvertently delete it on iOS. They would actually have to go into the browser settings and delete the database manually.

But the downside of WebSQL is that it may not be supported in the future from what I've read.

With IndexedDB, I am not clear when that data gets cleared. Will it also removed when cookies are deleted, or does the "databases" option in the Safari settings control this?

Is IndexedDB the better solution, as it will have better support than WebSQL in the future?

Are there other solutions that are more appropriate that I am not aware of?

Oarlock answered 6/10, 2011 at 5:45 Comment(0)
A
11

If you are wrapping in PhoneGap (or AppMobi - where I work), you're data is segmented to that app. A user can not go into Safari and clear the browser data/cookies and have that happen in your app. The only way they can delete it is by deleting the app.

I don't think IndexedDB is avaiable. Window.localStorage is (5 megs but I think it can grow), which is a KVP system.

I don't see them dropping WebSQL for a few years. The HTML5 spec isn't even ratified yet, so things could change again.

Since you are just storing strings, you can check out libraries like Lawnchair that will use different adapters (localStorage, WebSQL, etc) to store your data how you want since it appears you do not have complex data sets.

Accrue answered 13/10, 2011 at 20:0 Comment(3)
Thanks, I didn't know the storage would be segmented to that app if using a wrapper library. That solves my issue.Oarlock
window.localStorage is 5 Mb but as iOS is storing the data as UTF-16 it is efectivly 2.5 Mb. Also localStorage can't grow on iOS.Beading
@Stevo3000 You can get around that by transcoding your string to UTF-8, which is only a couple lines of code using JavaScript.Tswana
O
7

localStorage (aka Web Storage) and WebSQL are supported on all current mobile browsers except Opera Mini.

WebSQL, however, is considered "dead" as of November, 2010. The spec has a big fat "beware" label on it. It reads:

This document was on the W3C Recommendation track but specification work has stopped. The specification reached an impasse: all interested implementors have used the same SQL backend (Sqlite), but we need multiple independent implementations to proceed along a standardisation path.

As far as mobile browsers, IndexedDB is -- as of Dec. 2013 -- only supported in Android 4.4 (meaning no iOS Safari, Opera Mini/mobile or widespread Android Browser support).

See caniuse.com for the latest compatibility tables.

Oehsen answered 30/11, 2011 at 1:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.