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.