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.

9.1. A LocalStorage example application

 
 

9.2. Structuring a JavaScript library to maintain state

 
 
 

9.3. Using the LocalStorage API

 
 
 

9.4. Adding UI elements to complete the application

 
 
 

9.5. Other uses for LocalStorage

 
 
 

9.6. Summary

 
 
 

9.7. The complete code listings

 
 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest