Loading video player…

Saving State in the Browser (Overview)

Welcome to Saving State in the Browser. In this course, you’ll make a web page remember its data between visits, as people expect apps to.

In the video, you saw Sam’s recipe box, a page where Sam keeps the family’s recipes. Sam adds Pea and mint soup and reloads the page, and the soup is gone. That’s the problem this course solves.

In the finished box, the browser itself keeps the recipes, not a server. It starts with three starter recipes and keeps the soup after a reload. When its save is damaged, it falls back to those three starters and says why on the page:

What happens What Sam’s finished box shows
Sam adds Pea and mint soup, then reloads The three starters and the soup, still there
The save is damaged, then Sam reloads The three starter recipes, and Your saved recipes were damaged. Showing the starter recipes.

By the end of this course, you’ll know how to:

  • Loop over objects and follow paths into nested data
  • Save data as JSON text in localStorage and load it on every visit
  • Catch a damaged save and upgrade old saves with a version number
  • Make an app remember its data across reloads, and keep working when the saved data is missing, corrupt, or in an older shape

Before You Start

You need the JavaScript basics, including objects and arrays of objects, and you should know how a page reads a form and redraws a list from an array. Sam’s recipe box is that kind of page, and it’s the one you’ll work on. You also need:

  • A current version of Chrome or Edge
  • A code editor
  • A local server, such as Live Preview in your editor

How This Course Works

The course has three sections: Objects and Nested Data, Saving Data in the Browser, and Handling Errors and Bad Saves. Each section mixes text lessons and videos, and ends with an exercise you solve in the browser, with automated tests that check your code. In the project, Sam’s Recipe Box Remembers, you finish Sam’s box in three exercises, then explain it to the AI mentor. A quiz and a summary close the course.

First up is Loop Over an Object, where you look at the data Sam’s box has to save.

Download

Course Slides (.pdf)

2.3 MB
Download

Sample Code (.zip)

15.9 KB

Become a Member to join the conversation.