Storage API

In notebook:
FrontEndMasters Real-Time Web with Node.js
Created at:
2015-10-12
Updated:
2015-10-12
Tags:
JavaScript DOM Fundamentals
Video Course on Real-Time HTML5 with Node.jslocalstorage and sessionstorage 

they are now pretty stable. today they need the less a facade

they allow you to a persistence storage (about 5MB) 

twitter can cache latest tweets

they are very similar use but sessionstorage stays only for the session

localstorage is not being deleted if you delete your browsing history
data in local storage can stay there forever - unless you delete: you are responsible for cleaning it up

session cookies: are stored as long as the browser window is open - they are shared between tabs

sessionstorage is based in tabs session : each tab has a separate session. one tab or window doesn't pollute another 
key:value pairs 

in his facade library he had combined the two:

​var keep = h5.storage();

if you don't give an ​expires​ property it works like a localstorage (forever)
or you can decide how long you want to keep it

​var session = h5.storage({expires: "session"});​ for the session or
​var temp = h5.storage({expires: 5*60*1000})​ for five minutes

​keep.save({ prefs: {//...}});

​session.save({
  session_id: 123456,
  foo: "bar baz"
})
.discar(["foo"]);

​temp.save({
  active_login: session_get("session_id")
});

sessionid don't get transimtted at every request like session cookies

storage events

both APIs are evented : if you change anything it will fire off an event, that you can listen to it - even in another tab that use the same storage
e.g. you save something in one window will send the event to another that sync the data