2012-02-25

HTML5 Local Storage vs Session Storage

Some new features in HTML5 are really useful, like Web Storage, but you have to make sure you understand how it works and make sure you use it in the correct scenarios. There are actually two ways that HTML 5 Web Storage works: local and session storage. I ended causing some end-user confusion by using local storage all the time, so here is breakdown of how both work and when they should be used.

Local Storage
When using window.localStorage, the data associated to this object will never expire. So long as you don't uninstall your browser (or forcefully delete the data), the data held within this object will remain forever.

So a good example of using localStorage is when you have a web application where you create data and want to remember the last country selected, so the user doesn't always have to re-select it. So write your JavaScript code to remember the last country used and then retrieve it the next time the user comes to the page to preset the last selected country.

Session Storage
When using window.sessionStorage, this data will only be retained for a browser session. Meaning that once the user closes the browser instance, the data is gone.

This is useful when you have a search page and want to always retain and show the last criteria entered by the user. But once the user closes the browser, you want the data to be gone, so when he or she re-enters your application the next time, they start with a fresh page.

2 comments:

Anonymous said...

Does your site have a contact page? I'm having problems locating it but, I'd like to send you an e-mail.

I've got some recommendations for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it grow over time.

Also visit my blog post ... toddler hitting

yanmaneee said...

cheap jordans
louboutin outlet
chrome hearts outlet
hogan outlet
air max 97
nike epic react flyknit
balenciaga sneakers
cheap nba jerseys
christian louboutin shoes
golden goose