Cross browser HTML5 storage library

Jack picture Jack · Sep 19, 2012 · Viewed 7.3k times · Source

I have one requirement where should be stored locally when internet is not available. It should handle it in cross browser compatible way. Now as I know there are variety of options to store the data locally (indexedDB, WebSQL, localStorage). All I really want is a unified API. I don't want to detect and write code for several storage engines.

All I really care about is give a key, and give the data and it should be persisted across browser sessions/crashes.

After lot of googling the only library that I have actually come across is persisJS:

http://pablotron.org/?cid=1557

But it is roughly 4 1/2 years old. Is there anything better ormore reliable and newer than this?

Answer

Pez Cuckow picture Pez Cuckow · Sep 19, 2012

If you'd prefer to always be able to store

See http://www.jstorage.info/, specifically the Browser support section

If the browser is allowed to not cache if it doesn't support it

See locache: https://github.com/d0ugal/locache

The important bit for you being that is gracefully degrades and uses other mthods to store the information. It's also very easy to use and rather lightweight!

JavaScript framework for client side caching in the browser using DOM Storage with expiring values. With a memcache inspired API usage is very simple. Locache has no dependencies and is very small.

locache gracefully degrades when the browser doesn't support localStorage. Usually this will be IE6 or IE7, you wont get any errors, but caching attempts will be silently dropped and lookups will always appear to be a cache miss.