Recently, I have come across the Web SQL and IndexedDB APIs that are provided by browsers. What are the use cases for Web SQL and IndexedDB and when should I use one over the other?
-
10websql is deprecated – Josh Sep 26 '17 at 11:45
-
In that case please tell me some use cases of IndexedDB and where should we use it? @Josh – Utsav Sinha Sep 26 '17 at 13:28
-
when you want to store data in the browser, and would like to use a collection of objects that you can easily query and where using `localStorage` is not sufficient – Josh Sep 26 '17 at 14:51
-
2Why was this question closed? IMO, questions like this could still be answered presenting fact-based pros and cons and best use-cases for both solutions, so the users can choose based on their use-case. So, I'm not sure how this is "opinion-based". – kabirbaidhya Sep 02 '22 at 00:05
2 Answers
Web SQL is deprecated per https://www.w3.org/TR/webdatabase/.
You can use IndexedDB
if you need to store structured client specific data that you do not store in the server side or you do not want to request from the server every time.
Also as opposed to localStorage
, IndexedDB
is async so it is more performant. It supports indexing resulting in more efficient querying than localStorage
which is simply a key-value store. However, if your needs are simple, localStorage
might be a better option.
Here is a link that talks about different web storage options.
Here is a tutorial about how to use IndexedDB
for a progressive web app.

- 451
- 4
- 5
-
2IndexedDB is supposed to be more performant: https://nolanlawson.com/2015/09/29/indexeddb-websql-localstorage-what-blocks-the-dom/ – gdbj Jun 19 '19 at 14:39
Why not Web SQL?
The Web SQL database specification has been deprecated since November 2010. The browser vendors are not encouraged to support this technology and it's important that anyone reading this understands this. You can read more about Web SQL on its Wikipedia page. Now back to the other important segment of your question.
When to use the IndexedDB API?
You can use IndexedDB to store data of any JavaScript type, such as an object or array, without having to serialize it. All requests against the database are asynchronous. The browser's implementation allows you to set callbacks for when successes or errors occur. Modern abstractions over this implementation allow you to use promises instead.
One of the major use cases for IndexedDB is creating an offline database that will be synchronized with the actual database once online. This allows an application to continue to work while offline and persist past reloads. A now-dead famous example of this is Wunderlist, you can add and edit tasks even when offline. These operations go in a synchronization queue which is processed and emptied when the network is available again. This is how a lot of to-do list applications work when offline.

- 4,712
- 2
- 22
- 38

- 300
- 2
- 7