Chapter 9. Local storage and state management
This chapter covers
- Storing data locally in the browser
- Retrieving stored data and restoring application state
- Managing objects and properties using LocalStorage
Any application that handles a lot of user interaction and customization will benefit from the ability to store stateful information without the fuss and transactional support of sending it to the server and retrieving it when the user returns to the site. Consider a game site where the user wants to keep the last five highest scores. Only the highest score goes to the server for display; the rest are stored locally on the client for as long as the user wants. This reduces traffic and storage loads on the server while keeping the data accessible to the user.
Previous versions of HTML have a couple of options for storing this kind of data, but HTML5 goes a few steps further to give you a reasonably simple and stable means of keeping track of the information that your server solution doesn’t care about.
Typical kinds of values that might be stored locally are user preferences for sorting lists or previous search terms, but that certainly isn’t the end of the story.