HTML and CSS Reference
• IndexedDB—at the time of writing, experimental support
in Chrome 12, Firefox 5, and Internet Explorer 10—
Conveniently, the name Web SQL Database instantly gives you
a clue as to how it works: It uses SQL-based syntax to query a
local database. You may think that's great as you already know
SQL. The small potential issue is that the specification currently
has a stonking great sign notifying readers that the spec is no
longer being maintained. However, as it has such good sup-
port, particularly in the mobile space, I want to show you how
to use the API. In addition, Google uses Web SQL Database in
its mobile version of Gmail, so I'm confident the technology will
remain in browsers for quite some time to come.
IndexedDB's name is less descriptive, though you'd probably
be able to guess how it works. IndexedDB is a document data
store, akin to today's popular “NoSQL” databases, like Mon-
goDB. Essentially you have a key and you can store any data
type against that key, rather than having a set number and
type of columns as per traditional SQL databases. Interestingly,
IndexedDB puts events at the core of how you work with the
API. We'll talk more about that toward the end of the chapter.
Web Storage is a much simpler system in which you associate
a key with a value, compared to the amount of code required
when working with Web SQL Database or IndexedDB. Sup-
port for the Web Storage API is much better than the current
alternatives—but this should change with time leaving us with
a simple storage method (Web Storage) and larger data storage
(IndexedDB as support flushes through to the rest of the brows-
ers). I'll look at all three of these APIs, how they work, and how
to debug data in each system.
Web Storage typically has a limit of 5 MB (but browsers will
generally ask permission from the users if more than 5 MB is
required, and ask whether they want to allow the website to go
beyond the current default).
On the other side of the fence, the Web SQL Database specifi-
cation doesn't talk about limits, and it's up to the author to try to
gauge the total size of the database when it's created.
Then there's IndexedDB spec that doesn't mention limitations
(on the other, other side of the fence?), but it appears as Chrome
has a limit of 5 MB. It's unclear what the limits are in Firefox and
IE10. I am sure that as this specification gets better support in
the browsers, these limits will be well documented.