WJA
WJA

Reputation: 7004

Using Local Storage in Hybrid App Development as a "Local Database" - Dangerous or Useful?

I am building a hybrid app (Ionic) and only need local storage to save my database objects.

The app simply allows you to store, edit and view simple Notes.

Now, obviously I need to make sure that when the user saves a note, it remains stored on his phone.

My question is, are there any dangers of using window.localstorage in this context? Moreover, in which cases will the user loose all its data? One obvious case is when he deletes and re installs the app.

If local storage is not the way to go, what other ways are there (or does it always require a server side solution)?

Upvotes: 3

Views: 4346

Answers (2)

Hieu Nguyen
Hieu Nguyen

Reputation: 532

There are a few limits I found serious when using localStorage (in my case) including:

  • Storage limitation (~5MB) depend on browser (for more info here)
  • Only store string so you will end up convert into json (JSON.stringify) and query through json object
  • Once the mobile storage is full, it will force pure all the data inside storage

I end up looking for new candidate (sqlite seem promising but having some issue for iOS 10) On the other hand, if your application store small amount of data or mostly do transaction with online database. localStorage seems pretty good

  • Easy to use, already available for most browser
  • Json work like NoSQL

Upvotes: 1

Antonio F.
Antonio F.

Reputation: 73

Local storage is indeed an easy way to store data in a Cordova app. As pointed out by JohnAndrews all the data can be lost if the user clean the application data. On top of that LocalStorage present some limitations:

  • it very handy for key-value pairs but can be hard to store complex data
  • You cannot "query" your data
  • If you are using more than 1 webview on your mobile app you need your HTML5 content to came from the same domain, otherwise the LocalStorage data will not be shared across webviews.

If you want to have more info about data storage possibilities on Ionic (Cordova) apps check their official docs http://cordova.apache.org/docs/en/4.0.0/cordova_storage_storage.md.html

Upvotes: 3

Related Questions