Chapter 10. Storing Your Data

On the Web, there are two places to store information: on the web server, or on the web client (the viewer’s computer). Certain types of data belong on one, while others work better on the other.

The web server is the place to store sensitive information and data you don’t want people tampering with. For example, if you fill your shopping cart at an online bookstore, your potential purchases are stored on the web server, as are the catalog of books, the history of past sales, and just about everything else. The only data your computer keeps is a tiny bit of tracking information that tells the website who you are, so it knows which shopping cart is yours. Even with HTML5, there’s no reason to change this setup—it’s safe, secure, and efficient.

But server-side storage isn’t the best bet for every website. Sometimes, it’s easier to keep nonessential information on the web surfer’s computer. For example, local storage makes sense for user preferences (for example, settings that influence how the web page tailors its display) and application state (a snapshot of where the web application is right now, so the web visitor can pick up at the same spot later on). And if the data takes time to calculate or retrieve from the web server, you may be able to improve performance by storing it on the visitor’s computer.

Before HTML5, the only way to get local storage was to use cookies, a mechanism originally devised to transmit small bits of identifying ...

Get HTML5: The Missing Manual, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.