From the course: JavaScript: Client-Side Data Storage

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

When to use one over the other

When to use one over the other - JavaScript Tutorial

From the course: JavaScript: Client-Side Data Storage

Start my 1-month free trial

When to use one over the other

- [Instructor] While your use case may differ and in the end, the question will always be about keeping the data longer or until your browser close, lemme suggest a few best practices of when to use one over the other. When you want to maintain a state of your application, say a shopping cart, and want to control how long the state remains, use localStorage. With timers in your code, you can set how long the information remains with a persistent localStorage and them remove it whenever you feel is appropriate. Also, any personalized element of the site that doesn't place the privacy of the user in danger is a good use case for localStorage. For example, the first name of the user when they go back to your site or application, preferences related to the website, anything that makes the experience of the user better without compromising their privacy. This brings us to the next item. When the privacy of users is a concern and you'd like to need to use web storage, use sessionStorage…

Contents