When should I use Web SQL versus IndexedDB? [closed]
Asked Answered
J

2

43

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?

Jarvisjary answered 26/9, 2017 at 6:1 Comment(4)
websql is deprecatedArsphenamine
In that case please tell me some use cases of IndexedDB and where should we use it? @ArsphenamineJarvisjary
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 sufficientArsphenamine
Why 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".Scholarship
W
48

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.

Waldack answered 22/4, 2018 at 5:10 Comment(1)
IndexedDB is supposed to be more performant: nolanlawson.com/2015/09/29/…Tinsmith
M
20

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.

Martlet answered 19/2, 2020 at 17:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.