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 three potentially dealbreaking downsides:
HTTP request, thereby slowing down your web application by needlessly transmitting the same data over and over.HTTP request, thereby sending data unencrypted over the internet.What we really want is
A BRIEF HISTORY OF LOCAL STORAGE HACKS BEFORE HTML5
DHTML Behaviors, and one of these behaviors was called userData.userData allows web pages to store up to 64 KB of data per domain, in a hierarchical XML-based structure.Adobe introduced a feature in Flash 6 that gained the unfortunate and misleading name of Flash cookies.It allows Flash objects to store up to 100 KB of data per domain.By 2006, Flash 8 with accessing LSOs from JavaScript became an order of magnitude easier and faster. Brad rewrote AMASS and integrated it into the popular Dojo Toolkit under the moniker dojox.storage. Flash gives each domain 100 KB of storage for free. Beyond that, it prompts the user for each order of magnitude increase in data storage (1 Mb, 10 Mb, and so on).
dojox.storage could auto-detect and provide a unified interface on top of Adobe Flash, Gears, Adobe AIR, and an early prototype of HTML5 storage that was only implemented in older versions of Firefox.INTRODUCING HTML5 STORAGE
HTML5 Storage is a specification named Web Storage,certain browser vendors also refer to it as Local Storage or DOM Storage.what is HTML5 Storage?
key/value pairs locally, within the client web browser,like cookies.this data persists even after you navigate away from the web site, close your browser tab, exit your browser, or what have you.
USING HTML5 STORAGE
named key, then you can retrieve that data with the same key,the named key is a string. The data can be any type supported by JavaScript, including strings, Booleans, integers, or floats.
the data is actually stored as a string.
Calling setItem() with a named key that already exists will silently overwrite the previous value.Calling getItem() with a non-existent key will return null rather than throw an exception.Like other JavaScript objects, you can treat the localStorage object as an
associative array,instead of using thegetItem() andsetItem() methods, you can simply usesquare brackets`.
Example:
var foo = localStorage.getItem("bar");
localStorage.setItem("bar", foo);
…could be rewritten to use square bracket syntax instead:
var foo = localStorage["bar"];
localStorage["bar"] = foo;
Calling removeItem() it’s a methods for removing the value for a given named key, and clearing the entire storage area that is deleting all the keys and values at once.Example:
interface Storage {
deleter void removeItem(in DOMString key);
void clear();
};
Calling removeItem() with a non-existent key will do nothing.
key() it’s a property to get the total number of values in the storage area, and to iterate through all of the keys by index (to get the name of each key).EXample:
interface Storage {
readonly attribute unsigned long length;
getter DOMString key(in unsigned long index);
};
If you call key() with an index that is not between 0–(length-1), the function will return null.
HTML5 STORAGE IN ACTION
References:
@ MMIX–MMXI Mark Pilgrim /Local Storage