19

I have been over-viewing indexedDB recently, and I cannot seem to find a suitable use case that would not be better done using a server side database. Since the little hackathon competition I'm doing with my friends is creating an agenda web-app, I'll put my examples in that contest.

Just to make sure, I read that indexedDB is stored per site per browser. If this is so, the following ideas make no sense:

  • Storing user preferences. Since a user will most likely want his preferences saved across devices, it would seem better to save this on the server side.
  • Storing items / date that were recently viewed. Since this data is not structured and not data that will need to persist for a long time, wouldn't be easier to use localStorage.

I could go on with ideas that would fit better with a server side DB, localStorage or sessionStorage, so to cut to the chase, what are some example use cases that would fix indexedDB well?

2
  • 2
    I think the accepted answer to programmers.stackexchange.com/questions/219953/… might cover this question too. – Ixrec Apr 21 '15 at 23:59
  • According to me , when you have actual value in DB that means the table can easily be classified on any of the value, so u should create a index on that column. – user175451 Apr 22 '15 at 1:00
24

Server side relational databases are great for being a normalised primary data store. However, in many cases:

  • Persistent data storage isn't required because the data can easily be recalculated or retrieved again
  • It adds too much latency to make a minimum ~50ms HTTP request every time you want to access the data
  • Making frequent requests to data which is unlikely to have changed on the server side would place excessive strain on the database.

In these cases indexedDB can be suitable, which is most often in the context of a sophisticated web application.

A clearer example might be to look at the tables created by something like Google Docs/Drive:

Google drive

I assume in that scenario indexedDB might be used in several cases such as:

  • Storing edits without having to sync every single character change back to the server immediately
  • Ensuring edits can be synced to the server the next time the page is opened even if the user closed their browser instantly after making the edits originally
  • Avoiding having to reload things that don't change very often, such as a list of fonts or image resources every time the page is reloaded.

indexedDB is particularly useful if you want a client which can be used without an internet connection, which is becoming increasingly important as browser based applications replace more and more desktop applications.

Not the answer you're looking for? Browse other questions tagged or ask your own question.