The localStorage
The localStorage is the simplest and the most supported browser data store. At the moment of writing this book, it is supported in almost all the major browsers. As shown in the figure below, the only browser that does not support localStorage is Opera Mini:
The localStorage is a simple key/value database that is able to only store text. In localStorage, you have three main methods to access the data: setItem()
, getItem()
,and removeItem()
. With these three functions, you can manage the data in the store pretty well.
The downside of localStorage is that it does not have tables or collections, therefore, all the data is mixed; another issue with localStorage is that it is limited to 5 Mb of information. If your storage requirements are bigger than that, you will need IndexedDB.
Starting with localStorage
To store the data in the localStorage store, you need to call the setItem()
method in the localStorage
global object:
localStorage.setItem...