Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IndexedDB size keeps growing even though data saved doesn't change

I am using Redux Persist and LocalForage in my web application. I have a series of actions that are fired upon login that update some data about the user. The IndexedDB size after all actions are fired and the data is saved in the JSON format on indexedDB is ~1.4Mb.

Initial storage

However if I refresh the page thus triggering again the actions, or if log out and back in, even though the values inside IndexedDB DO NOT change (I have double checked with a JSON diff tool), the size of the storage keeps on growing. Eventually Chrome will clear some of it after it grows for a few MBs, but not going back to the initial correct size.

Big storage size

The IndexedDB JSON is exactly the same, no differences whatsoever, but huge difference in size. Does anyone know why this is happening and how can I prevent it? I also would like to know when/how often Chrome clears whatever data it is that is cluttering my IndexedDB, but I haven't been able to find any reference for it.

Thanks a lot

like image 890
slyfox42 Avatar asked Jul 30 '18 15:07

slyfox42


People also ask

Is IndexedDB persistent?

IndexedDB is a way for you to persistently store data inside a user's browser.

How do I get rid of IndexedDB?

In Chrome, go to "Settings" (or "Preferences" under the Chrome menu) Click "show advanced settings" (at the bottom of the page) Go to "Privacy" > "Content Settings" > "All cookies and Site Data" > find the domain where you created the IndexedDB. Hit either the "X" or click "Indexed Database" > Remove.

Is localStorage faster than IndexedDB?

IndexedDB offers several benefits over localStorage. For instance, IndexedDB doesn't block the DOM when used with a worker, unlike localStorage. However, localStorage is slightly faster than IndexedDB. The API of localStorage is also much easier to get started with, making it the more popular choice.

How much IndexedDB can store?

It may be useful for storing small amounts of session specific information, for example an IndexedDB key. It should be used with caution because it is synchronous and will block the main thread. It is limited to about 5MB and can contain only strings.


2 Answers

Chrome uses LevelDB as a backing store for Indexed DB. You can read more about LevelDB at: https://github.com/google/leveldb

LevelDB is optimized for fast reads and writes. Space is lazily reclaimed through compaction.

like image 99
Joshua Bell Avatar answered Sep 28 '22 04:09

Joshua Bell


I noticed the same behaviour in a Web-Application I am currently working on.
After doing some research, I found, that Chrome keeps old (deleted) Database-Files and only marks them as deleted. Also it will probably do some performance optimization which might increase space over time.
But once it reaches a specific size, it will automatically try to compress the database. I wanted to confirm this behaviour and added some code, which automatically reloads the webpage, once the data has been written into the Database.
In my case, the space needed by IndexedDB grew up to about 3.3MB. As soon as it reached this size, it has been compressed to about 1.3MB and started to grow again.

like image 33
Robert P Avatar answered Sep 28 '22 04:09

Robert P