问题
What are my alternatives to localStorage for persisting key/value pairs on the client? Ideally I'm looking for something that the user can't inadvertently delete (as they theoretically could with localStorage).
回答1:
With HTML5 your local storage options are limited to the following:
- localStorage
- cookies
- Web SQL (in WebKit and Opera)
- IndexedDB (in all modern decent browsers)
… however, users can delete data in any of these stores, and that is as it should be.
回答2:
An alternative could also be localForage, a js library that provides the ease of use of localStorage with all the advanced features of IndexedDB.
One of the benefits: you don’t have to convert your data structures to JSON in order to save them in the datastore.
Its API has support for ECMAScript 6 Promises, which provide a better way of handling asynchronous code. Unfortunately it doesn’t work well with any IE under 11.
来源:https://stackoverflow.com/questions/6909957/alternatives-to-html5-localstorage