JavaScript Cookies vs Local Storage vs Session




The ability to quickly store information on a user’s browser is an incredibly under used, powerful feature of JavaScript, and this is partially because of how unwieldy it used to be. In this video I am going to discuss the differences between cookies, local storage, and session storage, and how dealing with browser storage has become much easier since the initial release of cookies. I will also talk about how to use cookies, local storage, and session storage to store information in a users browser.

Twitter:

GitHub:
https://github.com/WebDevSimplified

CodePen:
https://codepen.io/WebDevSimplified

#LocalStorage #Cookies #SessionStorage

Original source


35 responses to “JavaScript Cookies vs Local Storage vs Session”

  1. This is fantastic, I've been scratching my head a lot lately trying to differentiate session, storage, and cookies and then lining it up with session on the server side. I've started looking at how other websites do it through the browser dev tools and cookies seem to be the weapon of choice.

  2. Please all stop using mb. There is no such thing as milibit… And before you say it doesn't matter, yes it matters!!!!! Can you tell me what he even thought with that? Is that MB or Mb? That matters… He said 4kb = kilo Bytes and 5mb = Mega bits… You know there is a difference right? Otherwise good stuff dude. Just stop with this nonsense…

  3. Encountered an interesting bug when working with redux-persist recently. Redux-persist was working just fine on my desktop computer by saving the current redux state to my web browser's local storage.

    I pulled from my local git repo on my mac and begin implementing a new action for my reducer. Next thing I know, all of my redux related functions are causing the application to break.

    As it turns out, I had created a logic error within my reducer, but fixing the logic error itself did not solve the problem. Why? Because redux-persist had already saved that logic error into that browsers local storage. Local storage also does not automatically purge itself, so the solution was for me to delete that browsers local storage and then re-run the application.

    Lucky for me, I had watched this useful video before using redux-persist to figure out how local storage actually works, as I had not previously used it in the past.

    Great learning experience and the video really helped!

Leave a Reply