Written by sushil on June 4, 2010 – 3:16 pm
HTML5 brings a whole set of new and exciting functionalities to the browser. One of these features is the new Web Storage API.
The new storage api is designed for two basic purposes - session storage and local storage.
Session Storage enables carrying out multiple transactions in different windows at the same time, in effect giving each window its own data store for current session.
While it sure is very helpful, the one that we find more interesting is local storage api.
Storing data on the client has been a challenge for Web developers for ages and HTTP Cookies have been the only way to accomplish that. Cookies do not handle this case well, because they are transmitted with every request - which is a performance hit if there is more and more data. Web Storage brings us the freedom to do this with local storage api.
Apart from uses like personalization or tracking user behavior, a much more significant one is caching data from your servers, on the client’s local machine. This allows you to avoid waiting for potentially slow calls back to your servers and minimizes the amount of data needed from your servers. It is often inefficient, insecure, or inappropriate to store that data on a server and this may amount to megabytes of user data, such as entire user-authored documents or a user’s mailbox.
The recommended storage space for each site is 5MB. This is way more than the 4KB space available via cookies. Stored data is accessible from multiple windows and lasts beyond current session and each site has its own separate storage area.
Another important aspect is the ease of use of the API. The Storage API is a classic name/value pair data structure. It has simple methods like getItem(name), setItem(name, value) and remove(name). For iterating over all of the name/value pairs, one can use the length property which gives you the total number of name/values pairs being stored, or go along with a key(index) method which returns a name from an array of all names used in storage.
It is already supported in the latest versions of all major browsers: Microsoft®, Internet Explorer®, Mozilla Firefox, Opera, Apple Safari, and Google Chrome. Even more importantly for mobile developers, it is supported in WebKit-based browsers like those found in the iPhone and phones using Android (version 2.0 or later) phones as well as other mobile browsers like Mozilla’s Fennec.
We, as developers, suddenly have a huge amount of storage space on the client. For mobile developers, it’s even more exciting as it really opens up the local caching of data. In addition to dramatic improvement of the performance of your application, local caching is key to enabling another new exciting capability of mobile Web applications - going offline.





















