HTML and CSS Reference
Web storage can only be used to store strings. This turns out not to be a huge issue due to
the fact we can serialize objects to strings easily with the JSON.stringify() function, and
de-serialize them with JSON.parse();
Another limitation of the Web storage API is that storage is limited to 5MB in most
coding for all strings. UTF-16 represents all characters as at least 2 byte (16 bit) sequences.
This is a limitation for most Western languages, since other UTF encodings (most notably
UTF-8) represent the characters in the Latin alphabet with a single byte.
was the precursor to UTF-16, and is a fixed length 2-byte encoding. This was
superseded as the number of code-points in the Unicode code space grew.
is approximately half the amount as could have been stored with UTF-8 (assuming we are
using mainly characters from the Latin alphabet). Effectively this reduces the size of Web
storage to 2.5MB: this is still far better than cookies, but is a limitation we need to bear in
mind when developing web applications.
I successfully managed to bypass this limit on one project by compressing
all data with the LZW compression algorithm. This effectively increased the
amount of data that could be stored to 50MB in this particular case (results will
vary depending on how repetitive data is).
This page provides implementations of the LZW algorithm in a variety of lan-
The implementation of our storage engine with Web storage will store each type of object
in an object of its own called an “object store” (if you are familiar with relational databases,
you can think of this object as a table). The properties of the object store will be the id