Chapter 7. The Past, Present, and Future of Local Storage for Web Applications

Diving In

Persistent local storage is one of the areas where native client applications have traditionally held an advantage over web applications. For native applications, the operating system typically provides an abstraction layer for storing and retrieving application-specific data like preferences or runtime state. These values may be stored in the registry, INI files, XML files, or some other place, according to platform convention. If your native client application needs local storage beyond key/value pairs, you can embed your own database, invent your own file format, or implement any number of other solutions.

Historically, web applications have had none of these luxuries. Cookies were invented early in the Web’s history, and indeed they can be used for persistent local storage of small amounts of data. But they have several potentially dealbreaking downsides:

  • Cookies are included with every HTTP request, thereby slowing down your web application by needlessly transmitting the same data over and over.

  • Cookies are included with every HTTP request, thereby sending data unencrypted over the Internet (unless your entire web application is served over SSL).

  • Cookies are limited to about 4 KB of data—enough to slow down your application (see above), but not enough to be terribly useful.

What we really want is:

  • A lot of storage space...

  • on the client...

  • that persists beyond a page refresh...

  • and isn’t ...

Get HTML5: Up and Running 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.