What is the difference between localForage and localStorage
Asked Answered
A

2

14

As I was looking to add an offline mode to an application, I dumped into localForage, which seems to be an interesting way to do so.

Still, I didn't get the difference it has with a simple localStorage API. Can anyone help me with that ?

Apivorous answered 29/12, 2016 at 9:16 Comment(0)
D
14

LocalStorage API is synchronous and accepts simple key value strings.

LocalForage leverage this simple interface with Promises to get/set values and gives the ability to store more than converted strings as data.

If you are familiar with the logic of LocalStorage and you are experimenting with something new I suggest you give it a try.

Reference: http://blog.teamtreehouse.com/using-localforage-offline-data-storage

Derwent answered 29/12, 2016 at 9:28 Comment(1)
Yes, from the libraries mentioned on Mozilla's documentation, localForage seems the simplest one and is easy as LocalStorage.Bidden
H
6

The benefits of LocalForage appear to be that it uses IndexedDB (with fallback to WebSQL or LocalStorage) as the storage backend. This allows it to be faster as well as not blocking execution of other code on long operations as it's API uses asynchronous promises. It also supports storing more than just strings unlike LocalStorage.

This is a good overview of LocalForage: https://hacks.mozilla.org/2014/02/localforage-offline-storage-improved/

Huntingdonshire answered 4/2, 2020 at 11:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.