Quantcast

HTML5: Web Data Storage Methods

Having discussed the basic differences between HTML5 and the previous versions of HTML, our main focus in this article would be discussing the data storage methods employed in HTML5. HTML5 maintains two basic methods for data storage: Permanent storage of data known as ‘localStorage’ and temporary storage of data for specific sessions known as ‘sessionStorage’. Previous versions of HTML did store data but that was done through cookies and two disadvantages govern data storage by cookies: First, cookies are unable to store large amount of data and second, data is stored with cookies with each request to the server. On the contrary, in HTML5, data is stored only when asked for, not with every subsequent request after establishing the connection with server.

The first method, the localStorage object stores the data with no time limit. The data will be available the next day, week, or year. For example, consider this piece of code: 

In the above code, number of visitors to a certain web page are observed and stored. Since this count needs to be permanent and should remain intact after connection with server is lost, it is made permanent.

The second method, the sessionStorage object stores the data for one session. The data is deleted when the user closes the browser window. Consider the code below:

The above code is used to store the number of times a specific user has visited a specific page during some particular sessions. After the connection is lost, that count is also lost since it was only for one session. Keeping in consideration the requirements of the developers and hosts, any of the above two methods can be utilized.

Looking for a quality hosting service? here are a few I suggest.
BlueHost | HostGator | Media Temple
Admin
Admin
Ali has been an entrepreneur in web, video and related technologies. Having worked with many business across the globe, Ali stands truly a great pillar in the business working with him.