User Session Storage

Typing the username each time you reload the page gets tedious. It would be better to store that username in the browser. For simple storage, the browser provides two APIs for storing key/value pairs (with one limitation – the value must be a string). These are localStorage and sessionStorage. The data stored in localStorage and sessionStorage is associated with your web application’s server address. Code from different sites cannot access each other’s data.

Using localStorage would work. But you might only want to keep the username until you close the tab or the window, so in this case you will use the sessionStorage API. It is just like localStorage, but the data is erased when the browsing session ends (either ...

Get Front-End Web Development: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.