Cookie, Web Storage, and IndexedDB
Storage encompasses Cookies, Web Storage (comprising Session Storage and Local Storage), and IndexedDB.
Cookies are used for client-side storage of session information.
The Cookie specification requires servers to include session information in their HTTP responses by sending a Set-Cookie header. Below is an HTTP response containing this header:
HTTP/1.1 200 ok
Content-type: text/html
Set-Cookie: name=value
Other-header: other-header-value
Components of a Cookie
- Name: A unique identifier representing the cookie's name.
- Value: The string value stored within the cookie.
- Domain: The domain for which the cookie is valid.
- Path: The URL path; cookies are sent to the server only if the request URL includes this path.
- Expires: A timestamp indicating when the browser should delete the cookie.
- Secure Flag: When set, the cookie is transmitted to the server only over an SSL secure connection.
Web Storage
Web Storage is used for storing session data and for persisting large amounts of data across sessions.
Web Storage consists of two objects:
localStorage: Provides permanent storage.sessionStorage: Provides storage that persists across sessions.
IndexedDB
IndexedDB is an object database that supports indexing.