30 Days Of JavaScript

Day 19: LocalStorage

Lesson 0: Intro

So far everything we have made goes away when we refresh the screen. That's because the data we are changing is stored in memory and not in any form of long term storage, we're not saving to a database or to files on disk.

Let's change that today, we are going to run through a couple of really simple examples to see how we can save data to LocalStorage. That way when you refresh the page we can reload any use generated data.

These examples will be quick and simple but in future we will use this technique to save more complicated and interesting data.

So let's look at:

  • Saving data to LocalStorage
  • Getting data from LocalStorage
  • Editing data in LocalStorage
  • Deleting data from LocalStorage

Before we start, there is some debate on how "good" it is to store data in local storage, as while the data doesn't expire it can get cleared out by user generated actions, like "clear browsing history and data". It also has some potential security vulnerabilities that people highlight ... but then most things have security vulnerabilities so it's a trade off (as with all things related to security) between convenience and secureness.

Outline

Go Pro?

If you upgraded to pro, sign in here

  • About
  • Blog
  • Privacy
Looking to email me? You can get me on my first name at allthecode.co