HTML5 and CSS3, Second Edition

(singke) #1
Safari on iOS and Android 2.0’s web browser. Technically, they’re not all part
of the HTML5 specification anymore, as they’ve been spun off into their own
specifications.

Although these new mechanisms can’t replace cookies intended to be shared
between the client and the server—like in the case of web frameworks that
use the cookies to maintain state across requests—they can be employed to
store data that only users care about, such as visual settings or preferences.
They also come in handy for building mobile applications that can run in the
browser but are not constantly connected to the Internet. Many web
applications currently call back to a server to save user data, but with these
new storage mechanisms, an Internet connection is no longer an absolute
necessity. User data could be stored locally and backed up or synchronized
when necessary.

When you combine these methods with HTML5’s new offline features, right
in the browser you can build complete database applications that work on a
wide variety of platforms, from desktops to tablets and smartphones. In this
chapter, you’ll learn how to use these techniques to persist user settings and
create a simple notes database.

We’ll delve into the following features:


localStorage
Stores data in key/value pairs, tied to a domain, and persists across
browser sessions. [C5, F3.5, S4, IE8, O10.5, iOS3.2, A2.1]

sessionStorage
Stores data in key/value pairs, tied to a domain, and is erased when a
browser session ends. [C5, F3.5, S4, IE8, O10.5, iOS3.2, A2.1]

IndexedDB
An in-browser object store that persists across sessions. [C25, F10, IE10]

Web SQL Databases
Fully relational databases with support for creating tables, inserts,
updates, deletes, and selects, with transactions. Tied to a domain and
persistent across sessions. No longer an active specification. [C5, S3.2,
O10.5, iOS3.2, A2]

Offline Web Applications
Defines files to be cached for offline use, allowing applications to run
without an Internet connection. [C4, F3.5, S4, O10.6, iOS3.2, A2]

Chapter 9. Saving Data on the Client • 184


Download from Wow! eBook <www.wowebook.com> report erratum • discuss

Free download pdf