Versioning the database of IndexedDB

IndexedDB is a client-side database, and developers don’t have full-time control over it.

For example, consider a scenario where we update the database version to 2 while a user is still using our web app with a version 1 database. The user won’t be notified until and unless the page is refreshed.

Example

Our web app currently uses version 1 of the School database. When a user visits our web app for the first time, our code tries to open the School database with version 1. If the School database isn’t present in the user’s browser, a new database is created with version 1.

Let’s write the code to demonstrate the scenario above:

Get hands-on with 1400+ tech skills courses.