HTML and CSS Reference
In-Depth Information
"[object Object]"
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
browsers. If this limit was not small enough, JavaScript uses UTF-16 as the character en-
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.
//
The JavaScript specification permits the use of either UTF-16 or UCS-2. UCS-2
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.
Due to the fact JavaScript uses UTF-16, the amount of character data it can store in 5MB
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-
guages including JavaScript:
http://rosettacode.org/wiki/LZW_compression
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
 
Search WWH ::




Custom Search