Cookies are included with every HTTP request Cookies are naturally unencripted Cookies are limited to about 4kb of data
What we want:
- A lot of Storage
- On the Client Side
- That persis beyond page refresh
- And isn't transmitted to the server
DOM Storage - A way for webpages to store named key/value pairs locally in the client browser
function supports_html5_storage() {
try {
return 'localStorage' in window && window['localStorage'] !== null;
} catch (e) {
return false;
}
}
if (Modernizr.localstorage) {
// window.localStorage is available!
} else {
// no native support for HTML5 storage :(
// maybe try dojox.storage or a third-party solution
}
HTML Storage is based on Key/Value pairs, you store data based on the named key, then retrieve it with the key. - The data type can be any but it is stored as a string
You will need to use parseInt() and parseFloat() to coerce the strings into the data types
var foo = localStorage.getItem("bar");
// ...
localStorage.setItem("bar", foo);
Add an event listener to a 'storage' action
openDatabase('documents', '1.0', 'Local document storage', 5*1024*1024, function (db) {
db.changeVersion('', '1.0', function (t) {
t.executeSql('CREATE TABLE docids (id, name)');
}, error);
});