srashtisj
srashtisj

Reputation: 151

Store huge data in localStorage

I am trying to store an array in localStorage, It's working for 3000 records, but when records increases to 5-10 thousand code breaks.

Is there is anything so I can store huge data in localStorage.

Upvotes: 4

Views: 7804

Answers (2)

Soviut
Soviut

Reputation: 91525

LocalStorage has size limits that vary depending on the browser. This is to prevent malicious scripts from filling a user's hard drive.

You can test your browser's localStorage limits here: https://arty.name/localstorage.html

The simple answer is, you shouldn't try to store more than 5MB-10MB of data on the client, depending on the browser. Needing to store that much local data is a sign that you probably need to come up with a better solution.

One other possibility for storing data locally is IndexedDB, which has reasonable compatibility across modern browsers. It's a object store which acts a lot like document databases such as MongoDB. You can store objects without converting them to strings and you can query those objects the way you would a database.

Most browsers seem to have a "soft" limit of around 5MB on IndexedDB storage. It's a soft limit because it's not necessarily enforced so you can go store much more if the browser allows it. Your mileage may vary.

Upvotes: 6

Ananya
Ananya

Reputation: 211

Max size for localstorage is 5MB for preventing malicious scripts from filling a user's hard drive. You can go for IndexedDB which is compatible with all modern browsers. The minimum or soft limit is 5MB- the browser will ask for permission to store the data. Maximum storage is the limit of your hardrive disk, as all of the data is stored locally on your machine disk. Basically if you have 20GB free storage than you can use all of the storage for IndexedDB.

Upvotes: 3

Related Questions