Using browser storage
What are the main differences between the 3 browser storage options?

Search for a command to run...
What are the main differences between the 3 browser storage options?

No comments yet. Be the first to comment.
What libraries I would use to start a React app in 2025 — and why
A breakdown of the most common AWS options for deploying static front-end applications.

Troubleshooting Azure DevOps and Microsoft authentication errors caused by IPv6.

Helping uncover what's silently breaking your web application behind corporate firewalls.

Overview and tutorial on implementing DataDog RUM.

There are 3 main storage options within the browser. Use the following information to decide which option to use for your use case.
Session storage is a browser storage only accessible through client-side JavaScript in which the data stored is automatically deleted when the user closes the browser tab or window.
Expiration: On tab close
Storage capacity: 5MB
Accessibility: Current tab
sessionStorage.setItem("firstName", "John");
sessionStorage.setItem("lastName", "Doe");
sessionStorage.getItem("firstName"); // John
localStorage.removeItem("firstName");
Local storage is a browser storage only accessible through client-side JavaScript in which the data persists in the browser’s memory upon page refresh or window/tab close.
Expiration: Never
Storage capacity: 10MB
Accessibility: Any window or tab with same origin
localStroage.setItem("firstName", "John");
localStroage.setItem("lastName", "Doe");
localStorage.getItem("firstName") // John
sessionStorage.removeItem("firstName");
Cookies are another form of browser storage only accessible by the server and not by the client-side JavaScript. The data stored in cookies are persistent upon page refresh or window/tab close, until the expired date passes.
Expiration: Manually set
Storage capacity: 4KB
Accessibility: Any window or tab with same origin
document.cookie = "firstName=John; expires=${new Date(2025, 0, 1).toUTCString()}"; // 01-01-2025
document.cookie = "lastName=Doe; expires=${new Date(9999, 0, 1).toUTCString()}"; // Never expires
document.cookie // firstName=John; lastName=Doe
document.cookie = "firstName=; expires=Thu, 01 Jan 1970 00:00:00 GMT"