Read: 13 - Local Storage and How To Use It On Websites
Local Storage and How To Use It On Websites
- Why would a developer use local storage for a web application? The main problem with HTTP as the main transport layer of the Web is that it is stateless. This means that when you use an application and then close it, its state will be reset the next time you open it. If you close an application on your desktop and re-open it, its most recent state is restored. This is why, as a developer, you need to store the state of your interface somewhere. Normally, this is done server-side, and you would check the user name to know which state to revert to. But what if you don’t want to force people to sign up? This is where local storage comes in. You would keep a key on the user’s computer and read it out when the user returns.
- What information should not be stored in local storage? Of course, any powerful technology comes with the danger of people abusing it for darker purposes. Samy, the man behind the “Samy is my hero” MySpace worm, recently released a rather scary demo called Evercookie, which shows how to exploit all kind of techniques, including local storage, to store information of a user on their computer even when cookies are turned off. This code could be used in all kinds of ways, and to date there is no way around it.
- Local storage can store what type of data? How would you convert it to that type before storing? Using local storage in modern browsers is ridiculously easy. All you have to do is modify the localStorage object in JavaScript. You can do that directly or (and this is probably cleaner) use the setItem() and getItem() method: localStorage.setItem(‘favoriteflavor’,’vanilla’); You can also use sessionStorage instead of localStorage if you want the data to be maintained only until the browser window closes.
REFERENCES
https://www.smashingmagazine.com/2010/10/local-storage-and-how-to-use-it/