HTML5 Web Storage

HTML5 comes with two objects for storing data in the client machine.

localstorage – There is no time limit for the data stored
sessionstorage – Data is stored for one session.

Cookies were used for this purpose, but cookies cannot be used if the data amount is large and they are also slow and ineffective as these cookies are passed to server on every request.
In HTML5 data is not passed every time whenever there is a server request. The data is sent only when the particular information is requested by the server. This will help a lot in increasing server performance.

Different websites store their data in different areas and these data can be accessed by the particular server only.

Javascript is used to store and access the data in HTML5

 

The localStorage Object

 

There is no time limit for the data stored in the local object. The data will be available around the year till it is deleted intentionally.

 

Creating a localStorage:

 

The example below counts the number of times a user has visited a page

The sessionStorage Object

 

The session storage object stores the data for one session. The data in the browser is deleted once the user closes the window.

Creating session storage.

The example below counts the number of times a user has visited a particular page during the current session