improves the offline experience of your web app by using asynchronous storage
(IndexedDB or WebSQL) with a simple,
localForage uses localStorage in browsers with no IndexedDB or WebSQL support. See the wiki for detailed compatibility info.
Try the live example.
npm install localforage
bower install localforage
localForage is compatible with browserify.
Lost? Need help? Try the localForage API documentation.
If you're stuck using the library, running the tests, or want to contribute
to localForage, you can visit
irc.freenode.net and head to the
channel to ask questions about localForage.
The best person to ask about localForage is tofumatt, who is usually online from 10am-8pm GMT.
Since Safari 10.1 we default to IndexedDB; see the CHANGELOG for more info.
Because localForage uses async storage, it has an async API. It's otherwise exactly the same as the localStorage API.
localForage has a dual API that allows you to either use Node-style callbacks or Promises. If you are unsure which one is right for you, it's recommended to use Promises.
Here's an example of the Node-style callback form:
And the Promise form:
For more examples, please visit the API docs.
You can store any type in localForage; you aren't limited to strings like in
localStorage. Even if localStorage is your storage backend, localForage
JSON.stringify() when getting/setting
localForage supports storing all native JS objects that can be serialized to JSON, as well as ArrayBuffers, Blobs, and TypedArrays. Check the API docs for a full list of types supported by localForage.
All types are supported in every storage backend, though storage limits in localStorage make storing many large Blobs impossible.
You can set database information with the
Available options are
Note: you must call
config() before you interact with your data. This
config() before using
You can create multiple instances of localForage that point to different stores
createInstance. All the configuration options used by
config are supported.
var store = localforage;var otherStore = localforage;// Setting the key on one of these doesn't affect the other.store;otherStore;
You can use localForage with RequireJS:
localForage 1.3+ works with both Browserify and Webpack. If you're using an earlier version of localForage and are having issues with Browserify or Webpack, please upgrade to 1.3.0 or above.
localforage from being parsed by webpack using the following conf :
module:noParse: /node_modules\/localforage\/dist\/localforage.js/loaders: ...
Otherwise you should use one of the following:
;// or, in case that the typescript version that you are using// doesn't support ES6 style imports for UMD modules like localForage;
If you use a framework listed, there's a localForage storage driver for the models in your framework so you can store data offline with localForage. We have drivers for the following frameworks:
If you have a driver you'd like listed, please open an issue to have it added to this list.
You can create your own driver if you want; see the
defineDriver API docs.
There is a list of custom drivers on the wiki.
To work on localForage, you should start by
forking it and installing its
USERNAME with your GitHub username and run the
# Install bower globally if you don't have it:npm install -g bower# Replace USERNAME with your GitHub username:git clone email@example.com:USERNAME/localForage.gitcd localForagenpm installbower install
Omitting the bower dependencies will cause the tests to fail!
You need PhantomJS installed to run local tests. Run
npm test (or,
grunt test). Your code must also pass the
localForage is designed to run in the browser, so the tests explicitly require a browser environment. Local tests are run on a headless WebKit (using PhantomJS).
When you submit a pull request, tests will be run against all browsers that localForage supports on Travis CI using Sauce Labs.
This program is free software; it is distributed under an Apache License.