Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between localForage and localStorage

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 ?

like image 450
Ismail H Avatar asked Dec 29 '16 09:12

Ismail H


People also ask

Should I use IndexedDB or localStorage?

If you want to store structured data on the client side, IndexedDB is the better choice, especially since localStorage isn't built to store sensitive information. But if you're storing a simple, small amount of key-value pair data, use localStorage.

Is localForage secure?

Local storage is inherently no more secure than using cookies. When that's understood, the object can be used to store data that's insignificant from a security standpoint.

What is local forage?

localForage is a JavaScript library that improves the offline experience of your web app by using an asynchronous data store with a simple, localStorage -like API. It allows developers to store many types of data instead of just strings.

When should you not use localStorage?

The following are limitations, and also ways to NOT use localStorage : Do not store sensitive user information in localStorage. It is not a substitute for a server based database as information is only stored on the browser. localStorage is limited to 5MB across all major browsers.


2 Answers

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

like image 67
George Antonakos Avatar answered Oct 19 '22 02:10

George Antonakos


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/

like image 39
Michael Lawton Avatar answered Oct 19 '22 02:10

Michael Lawton