angularjscordovamobilelocal-storage

Which is the best way to store local data with cordova?


I will programm an cordova application with angular js and i would like to make it work for IOS android and ( if possible ) windows phone. My app don't require internet or account so i think the best way to store data is to use the local data. I saw 3 way to do it on cordova documentation (http://cordova.apache.org/docs/en/6.x/cordova/storage/storage.html#page-toc-source ) and none of this 3 methods seems good. 1st say that data could be deleted on IOS, 2 is depreciated, 3rd does not work on IOS.

But is there other way to do it ? I mean it seems to be a very basic problem ( store some datas as preferences .. ) but the only way I found are some plugins ( i don't know if th're good or if they will be develop for a long time etc )

Do you have any advices ?

Thanks for reading and sorry english is not my main language.


Solution

  • You have all of the common HTML methods available. Out of those, localStorage is an easy choice for simple low volume data (like a few basic persisted config settings) and easy initial development with a web browser. There are some plugins you can use as an alternative to store app settings though such as this one:

    Personally I'd be inclined to go with localStorage if your needs are simple, as shown in the link you originally provided.

    If you want a local db instead, many folks would say don't go with WebSQL (SQLite) without using a Cordova SQLite plug-in to move your db to the device's native side, as WebSQL under HTML5 may be deprecated or inconsistently implemented. The downside to using one of these plug-ins is that some are buggy, and you can no longer do initial dev work in a web browser without coding your own fallback to HTML5, and the fallback will behave differently. (There are enough syntactical differences to cause problems.)

    However, there is an alternative database solution: PouchDB, which works on a dev web browser too, gives you a nice local CouchDB API and abstraction for a web technology like IndexedDB, and is an option to more easily synch with a remote DB in future, if you end up expanding your app down the line:

    It also can work with the SQLite plug-ins as detailed in the adapters link above. I'd only seriously consider a Cordova SQLite plug-in if your local db is going to be over 50MB in size. Too much of a down-side otherwise IMHO.