Source: 63edb91e46663800083d0ea0--sebastiandedeyne-com-e11d52.netlify.app

Local or session storage?
We tend to grab straight for localStorage, but it’s not the only tool in our workbox. Let’s review their similarities and differences, and determine when to use which. localStorage and sessionStorage are part of the https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API have the same key/value mechanism.

localStorage.setItem('scheme', 'dark'); const colorScheme = localStorage.getItem('scheme'); sessionStorage.setItem('scheme', 'dark'); const colorScheme = sessionStorage.getItem('scheme'); They both store data as strings, but can store objects, arrays, and other primitive values as JSON with JSON.stringify and JSON.parse.

There are more ways to store data locally like https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies, https://developer.mozilla.org/en-US/docs/Web/API/History/state, or https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners