What is the difference between Local Storage, Indexeddb and Websql?

Asked

Viewed 390 times

9

I have a habit of using Local Storage to store JWT, I would like to know the difference between Local Storage, Indexeddb and Websql and when to use one or the other.

1 answer

6


Forget about Websql. It was supposed to be a relational database, but it was abandoned by the standard and today only works in browsers based on e=Chromium, without receiving attention, may even have become insecure.

Local Storage

It serves to store very simple data, it’s kind of a basic cache. For example you can store data that is a little more complex than you would use in a cookie to later use on the page that depends on it.

Basically it is a table hash, a dictionary with keys named through strings and that it holds normally basic values, nothing complex. It is persisted so the data stays from one session to another unless you explicitly delete it. And it’s obviously very simple to use your API since the functionality is limited. It’s more or less like persisting a huge JS object in it.

It can be configuration data and user preferences to use the page more interestingly.

Indexeddb

It can be considered a database to store much more information, to have much more complexity in what it puts there, in different ways, with more interesting commitments and more convenient for the purpose of storing diverse data. For example, it allows you to create indexes for the data, so you can access it efficiently in various ways. Can also handle data in a transactional way.

It’s not enough to be a complete database, especially not relational, which can compete with the kind of software you usually use on backend, but it can do a lot next to this. It will usually be used as a wider cache or for something that is PWA.

Obviously it’s a little more complicated to use it.

You can make an application that depends on a database on frontend, although it will almost always be a little exaggerated to do so.

I don’t know if anything changed, but it made little sense local Storage have an asynchronous API since it handles little data and in a simple way, Indexeddb this is fundamental and from the beginning the API was thought like this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.