There are loads of storage options for Ionic apps - localStorage, angular storage, localForage, WebSQL, IndexedDB, SQLite, File System and so on.
But which, really, is the best one?
Okay, so for different situations different things will be better. localStorage is perfectly adequate for things like settings (e.g. user gender or age, dark/light theme, allow/disallow Google Analytics or access to user location, etc) but for everything else?
I’m asking because some of the apps I want to make will store what I consider large amounts of text data. Andrew McGivery tested this all in 2013 http://mcgivery.com/localstorage-how-much-is-5mb/ and found that Chrome only allows about 2.5Mb in localStorage.
This may well be enough, but it seems like a really small amount these says, no? And if I’m not using one of the 5Mb services then I’ll really have to take the plunge and deal with SQLite. I’m fine with SQL, its all the methods that get me.
So for my current project, I designed it to be ONLINE first since it’s a huge point of the app is to use my data analytics tools. BUT, for things that don’t need it, I’ve started implementing types of offline first.
I am using purely local storage! I don’t have any images, documents, or big chunks of data to cache, just a bunch of lists and settings. I find that local storage is doing really well for that. I have wanted to look into SQLite but I have a hard time building out such a huge thing if I’m only using it for the minimal.
I’m interested as well to hear about success with SQLite?
It’s interesting because I’m only storing text data and in theory 5Mb is enough to contain the complete works of Shakespeare!
But it’s only enough to hold 30 seconds of high quality video!
That’s such a bonkers difference and its the issue that is plaguing me. If I learn to use SQLite or the File System I’ll have no problems with storing whatever I want, whenever. But it’s an order of magnitude harder to use. I built the app I’m working on now in jQM/PhoneGap Build and used localStorage. It worked. But now I’ve moved to Ionic and I’m thinking I may as well get used to the hardcore stuff.
On the other hand localForage - using IndexedDB, fallback to WebSQL, fallback to localStorage - seems pretty cool really.
Makes total sense. I really do think it depends on the scale of the app. I wouldn’t shy away from using both if you needed to. I am considering generating bar codes client side instead of server side (I do it VIA php right now then they GET the image) but to help offline-ability i would do it, save it, but I would save it either in the file system OR generate on app load.
I love how diverse app needs are. I am very familiar with MySQL and I would like to use something similar. I guess SQLite is close? I need to look into it further
Yeah, it’s similar. There are important differences though - the Date for example. There is no Date type so you have to use a string.
I’m not building any apps, at the moment, that use a server. I do want to build a focused messaging app in the future though, and it’ll take me a lot of research before I get started.
Oh interesting, that stresses me out Hahahaha. I use a lot of date/time management in my apps for the analytics. Servers aren’t too hard. Are you proficient in PHP?
It’s not too bad, syntax is fairly similar to JavaScript. I use SlimPHP (a framework) and it’s got some great routing features that make making an API really easy. I’ve also seen people do an API with something like NodeJS, or you could even use web sockets or something like Socket.io
Yeah, I remember a little of it. I built a DB web app with PHP and mySQL and it was fine. I did similar with ASP and MSIS and it was a nightmare. Worked though. PHP is fine and I’d happily learn it again if I felt I needed it. This was in the early 2000s though!
One of my issues with storage in Ionic is I don’t really get how things like Gmail, Facebook, WhatsApp, Stronglifts 5x5 (all apps I use) store their data.
I feel like with the mass amounts of data (like gmail, because it stores almost every deleted, archived, sent, and current emails) it’s probably a database solution. I know you can store images and such using different formats in MySQL. It’s not particularly recommended, but if you’re running it locally I don’t see why not!
My fitness app is all local storage though like I had said earlier. I can modify and manipulate the JSON objects that i’m storing with relative ease. I’m not confined to a specific database structure on the client side that has to match the server. Granted you could do a DB solution, and just have a key value pair type thing going on.
PHP is still totally relevant. Twitter’s framework is built using Java if I remember correctly, and Facebook actually is built on PHP, if that says anything for how resilient it is haha.
@xiaolong97427 How easy has it been to integrate it into your app?
I’ve found it really useful to just write a simple angular service which saves a single js object into localstorage using JSON.stringify and JSON.parse. It’s like using document storage, where you just have one large object with all of your settings and data, but most importantly it’s just extremely simple to implement and understand. I made a gist here if you want to check it out:
I’ve been using SQLite for my data-heavy app, Zed.
All my data comes from (and goes back to) a server in JSON format, so I thought using PouchDB on top of SQLite would make things easier. Unfortunately it really killed performance as I had to create at least two transactions for each item I was downloading from the server - one to check if it already existed, the next to either update or create the new item.
I don’t need to worry about overwriting local data so I ended up using https://github.com/psayre23/WebSQL and just running my own SQL queries. Much faster, and the wrapper helps make the SQL transactions easier to work with. (You will have to modify the library to use the SQLite plugin, but it’s one change in one line, if I remember right.)