While sharing a little about The Web Storage API, we checked the Chrome Developer Console and found out that there are some other options to store data in your browser.
In this article, we will cover the research done to understand these two other options to store data using our browser.
There are times when developers need to store a rather large amount of structured data such as files/blobs. The fact that this can be done for client-side storage is blowing my mind right now.
This feature is available in Web Workers.
IndexedDB is both a transactional database system and a JavaScript-based object-oriented database, meaning it lets you store and retrieve objects that are indexed with a key.
Have in mind these concepts:
Note: Like most web storage solutions, IndexedDB follows a same origin policy. So you cannot access stored data across different domains.
The API offers some interfaces to work with for us to interact with the DB properly and also it understands what we're trying to do with such objects.
For us to connect to a DB we call the function open()
on the indexedDB
attribute of a
window
object, let me show you with a piece of code.
// number one is the version, you can pass any other number
// as parameter there to set your version
window.indexedDB.open("NAME-OF-YOUR-DATABASE", 1);
// var IDBOpenDBRequest = indexedDB.open(name);
// var IDBOpenDBRequest = indexedDB.open(name, version);
Here we can see an example of a todo app using IndexedDB.