LocalForage – A fast and simple storage library for JavaScript
github.com
github.com
Some browsers like Firefox throw exceptions when you try to touch storage in private browsing mode. This can be super annoying since it tends to break pages that use storage and haven't been specially tested in that mode in that browser. A library-based memory fallback helps avoid that. AFAIK it's what Chrome does with storage in incognito mode: just save calls in RAM, return them if asked for, then throw it away when navigating.
There's a PR to add this for localforage but it's been stuck in purgatory for a while and seems to have some resistance despite the utility: https://github.com/localForage/localForage/pull/555
This could be just personal preference, but it seems far more likely to me that my expectation when storing values in localStorage would not match Chrome's apparent silent fallback of not storing that value. I'd much prefer to handle the error case.
IDK what you'd rather do in Chrome Incognito, Safari Private, Edge InPrivate, etc.
---
PS. If the OS registry entry for localStorage location is invalid or missing, IE will also throw an error.
1: But it's exclusively memory-backed and will be forgotten somewhere between 0 and 20 seconds after the last active page for the origin is gone. It is not persistent for the lifetime of the private browsing session. However, because Firefox has a back-forward cache ("bfcache") that keeps pages around (frozen) for a while after you navigate the window to another location, the storage may be kept alive for some time even with no active windows.
It keep tracks of expenses offline and sync states when you have connectivity again.
The app itself is a freight logistics tracking and scanning app which is meant to download and store a few hundred MB of carton data and be able to scan and process it offline and sync back to a server when online again.
With redux-persist and localforage it's been effortless to enable this. Parts of our store are whitelisted and are persisted to localforage every 300ms or so. When the app is loaded the next time it pulls the data from localforage and "rehydrates" the store with it so it's like we never left the page in question.