What are cookies, local storage and session storage and what are some differences?
All three of these are client-side storage solutions (i.e. a cookie is both client and server-side) that can be used to store data that is needed within client scripts between pages.
|Cookies||Small piece of data that a server sends to the user's browser that is then stored and sent back with future requests to the same server||4KB Storage - Server and client side reading - Supported by older browsers - Expiration varies||Logins, shopping carts, game scores, user preferences, tracking user behavior|
|LocalStorage||Window property (window.localStorage) that is saved across browser sessions. The data stored is not sent back to the server with each HTTP request, reducing traffic between client and server||5MB/10MB storage - Not as supported by older browsers - Never expires or removed, unless explicitly done so||Login forms remembering username, user preferences, custom settings|
|SessionStorage||Similar to LocalStorage, however, data does not persist across browsers. Data is only available during the page session.||5MB - Data will be deleted after session (browser) closed - Not as supported by older browsers||Use in cases where you do not want the data to persist over time|