HTML and CSS Reference
• Web storage: this is the simplest form of offline storage and supports name/value pairs
where the name and value must both be strings. Although this is a relatively simple storage
mechanism, and does come with a number of limitations, all major web browsers support
• Web SQL Database API: this API supports a relational database within the browser (sim-
ilar to MySQL). Although this has many advantages, particularly for developers already
familiar with relational databases and SQL, Chrome and IE have announced that they will
never support this API, therefore it is effectively dead.
• IndexedDB: (formerly WebSimpleDB) this API exposes an object store. Objects (or
simple data types) can be stored against a key, and retrieved either through this key, or
other indexes added to the record. IndexedDB supports a transactional model familiar to
database developers, but does not include a generic query language such as SQL. This is
a promising API, but is not yet supported by all browsers. In particular, Safari, and some
mobile browsers do not support this API.
In this chapter we will create a storage API that allows us to abstract the underlying storage
API from the web application. This means that the web application will not be aware which
underlying API it is using, which then allows the most appropriate API to be used (depend-
ing on browser support).
This approach is another example of a design pattern called the bridge pattern.
This chapter will provide implementations for both Web storage and IndexedDB. We will
refer to this abstraction as a “storage engine”.