Storing data locally or just using ajax?

You must Login before you can answer or comment on any questions.

Hey guys,

So I just posted this question on stack overflow because I think it relates to more than just Titanium, but it would be interesting to hear as many opinions on it as possible so I wanted to post it here as well.


Currently I'm building a few mobile apps (currently on iOS but later on Android)that retrieve information via ajax calls (returning JSON) from a Ruby on Rails application. This obviously applies to other applications as well that are using another source to return the JSON data.

The main question is WHEN to store the data and when to just use ajax calls to retrieve it. Currently, my apps do not store a single thing locally and instead require ajax calls for all data. I think for this example we can use the Twitter mobile app, which is one a lot of people are familiar with and has a lot of functionality that I'm wondering how they do it (more logically than technically).

Questions:

1) When you log in the first thing you see is a list of all of the items in your stream. That list is available offline. Does that mean that when you originally signed in, Twitter already went and pulled all of your last X (100?) stream items into a local database and then future views just pull it from there?

2) If you then put your phone on airplane mode (or just shut off mobile data) and click one of those tweets, it opens up the tweet page with all of that data. So now, it looks like they aren't pulling that information in via individually each time you visit a tweet page (which is what my app currently does and takes some time to load that data in and create the views). Does it make sense that they are probably just using the same information that they pulled in when creating your stream items?

3) Users. Is it better practice to (when viewing a users "profile" page for example) store a users data locally and then refresh on future visits, or just do pull in all of the data via ajax each time? In theory each requires an ajax call...

I think those are my main questions for now. If anyone has any thoughts on any of those things (or any other insights into mobile storage) that would be great! If anyone needs screenshots of anything I referenced please let me know and I'd be happy to get those for you.

Currently using:

Titanium Appcelerator for iOS

Ruby on Rails for Backend and remote storage

http://stackoverflow.com/questions/11113165/storing-data-locally-or-just-using-ajax-on-mobile-devices

— asked 12 months ago by Michael Fogg
2 Comments
  • refer this question. Good luck...

    — commented 12 months ago by nilesh kashid

  • Thanks! So it seems like that question (linked above) references the fact that it would be a good idea to store that information in an array. If say, for example, we chose to pull in (using twitter again as the example) a users first 100 tweets in the first pull, it seems like that question suggests that we store all of that information in a JSON array and then pull from that later. That would make sense, but is there a performance benefit to doing that vs storing the data in a local SQL database? If we store in the database you would be able to do lookups based on a tweets ID, vs. it seems like (and please correct me if I'm wrong) storing the JSON array would limit our ability to use that data in the future to mainly lookups based on the items index in that group (ie. something like tweets[0].tweet.text).

    — commented 12 months ago by Michael Fogg

1 Answer

Accepted Answer

Generally you have an issue: Ajax data-per-request vs. # of requests, so reducing on of them or both increases the Response time of your app. To achieve this you need to Cache the data. i.e. the profile:

once viewed you Cache the data, on next view you just compare last_update or similar, yes it requires a Ajax call but now the User does not recognize any loading indicators. There is a profile and everything is fine. If the device has no Internet you can out them in a Queue.

This is a lot of more work but if you want Bug Things successful... Keep in Mund that it also reduces your Server load.

— answered 12 months ago by Alexander Bauer
answer permalink
3 Comments
  • I hate this spelling correction on smartphones...

    — commented 12 months ago by Alexander Bauer

  • Server load is something that we are trying to be very aware of, so thanks for bringing that up as well. So when you say "Cache the data" do you mean actually cache it in the phones memory, or store it in something like an SQL database? In the example I used above (posted after you're response) I mentioned pulling in the first 100 tweets that a user had when they first log in (when we first populate their "stream" or whatever twitter calls it).

    Say I then store each of those in the database as an individual record in a table called "tweets". Now when I click on one, my "tweet" page would check the database for a record with that tweet id, if it finds one, pull in that data first and THEN send the ajax request (the user would already see the data so they wouldn't really notice it. If there is no tweet with that ID, then go and fetch the remote data? I'm not sure if the second scenerio would ever be possible as if they could click on it in the stream... we'd already have stored that tweets data.

    Is that kind of what you mean?

    — commented 12 months ago by Michael Fogg

  • Yes, I mean storing it in a database. As you described the User would see the last tweets while the app Checks for New Posts in the background showing small loading Animation somewhere so User can see that there happens something.

    — commented 12 months ago by Alexander Bauer

Your Answer

Think you can help? Login to answer this question!