using sessionStorage is totally fine. especially if you have to support things like ie8. We use it extensively. localStorage is also useful for message passing and intertab coms.
You should be aware that:
- there is a 5MB limit
- all values are a key/value pair storing values as a STRING
- you can just JSON to store more complex values.
- in firefox the storage is shared across ALL sessions of that top level domain- eg.
myapp.someting.com &
cms.something.com both share the 5mb space. except they do not have access to eachothers session, as so cannot clean up. This can be annoying. Especially since it is NOT removed on browser close, as state is recreated. I cant find the bug link, but people have been complaining. We ran into the issue, and just had to reduce the size of what we store.
other trivial notes that you might find interesting:
- internet explorer 8-10 (not sure about 11) break the spec for the 'storage' event. When you change a value, you can listen on other tabs/windows for a storage event (for localStorage) and use this to keep tabs in sync. The event should be sent out to OTHER tabs. IE sends the event to itself (the tab of origin) also. You need to wrap the value and id your tabs to fix this afaik.
- localStorage is shared memory. chrome runs different processes for each tab. reads and writes (getItem, setItem) are atomic, meaning that you will never have the issue that two tabs write at the same time, but you DO have the issue that since your read, another tab might have mutated the value - even if you have the read and write (if you are appending to an array for instance) in consecutive lines of javascript. There is no way to reliably *lock the localstorage, via a mutex or semaphore - to allow for a 'transaction' to be performed, since creating a spinlock requires processing on the background tabs, and chrome buffers and limits processing for background tabs. SO, you can delegate a *master, via consensus. If you need a reliable way to write and sync data between tabs. Ill be hopefully releasing code that ive made for this at some point - its pretty simple, just use the storage event with heartbeats, etc, to delegate master.
But in general, for simple usage, and just hydrating state between page refreshes.. yes. its perfect for that ;P
cheers