Through the magic of GitHub Pages I’ve got multiple static web apps hosted at the same domain. That means offline storage (IndexedDB, WebSQL, LocalStorage) for these apps is in the same bucket. Luckily localForage provides a way to keep the data separated.
Versions used below
Edited on 27 Feb 2015: Previously I said you need to set
storeName but actually only
name is required for namespacing data.
Set a custom name
The value for
name should be unique across all other localForage instances on the domain. The value can be anything reasonable, I usually use my app’s name.
If you just need to keep your app’s localForage data separate from other apps on the same domain, you’re done.
Creating multiple instances of localForage
Since 0.9.3 you can make more localForage instances using
localforage.createInstance(). The options accepted by
localforage.config() are also accepted here.
At this point you’d have two localForage instances:
Full example with multiple instances
I use native
Promise below so it works without polyfills in anything but IE.