简体   繁体   中英

Check if object fits into browser cache

I have a single page application, which loads a JSON data file from a server and displays it on the client. The data file only changes once per day, so after fetching it, I want to keep it cached on the client. So far, I have been using jStorage and am happy with the overall result. One thing is problematic though: according to the jStorage Browser support page , the cache size varies from browser to browser.

So my question: can I somehow find out if jStorage will be able to store all my data? The jStorage website itself does not give any clues to that.

Alternatively, since I'm only storing one big object, I could use a plug-in like sizeOf to check the object size before saving it, but I don't know if that is a reliable approach.

I am not sure how jStorage implements, you say 5mb so I guess it's using localstorage . Have you tried indexedDB which is browser native and theoretically limit to your hard drive capacity.

https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM