Search code examples
javascriptangularjslocal-storageionic-frameworkhybrid-mobile-app

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)?


Solution

  • 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