O'Reilly logo

HTML5: The Missing Manual by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 9. Data Storage

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. 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).

Before HTML5, the only way to get local storage was to use cookies, a mechanism that was originally devised to transmit small bits of identifying information between web browsers and web servers. Cookies work perfectly well for storing small amounts of data, but the JavaScript model for using them is a bit clunky. Cookies also force you to fiddle with expiry dates and needlessly send your data ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required