HMTL5 website allows a user to store data locally on your own computer, a fast and safe.

Before HTML5, Web pages using cookies to store user information locally. This information is stored in the HTTP headers as key-value pairs, and were attached to all user requests.

Now with HTML5, Web pages can store user information locally in a more efficient, because information stored locally will not be attached to all requests, only requests that are attached to really need that information. This way you can store lots of information from users browsing our web pages without affecting the performance of them.

There are 2 ways to store information locally on the client:

1. - LocalStorage

User data that is stored with "localStorage", are stored with no expiration date, ie, forever or until you explicitly delete this information from your browser.

All browsers offer the option to enable users to delete information that web pages stored on it.

Data is stored using key-value pairs.

LocalStorage syntax:


Example localStorage

If you want to store the user name "Peter", so the next time you visit, display a custom message, you can save this:"Peter";

2. - SessionStorage

The data about the user, stored locally "sessionStorage" are maintained throughout the user session, ie while the user does not close your browser.

When the browser is closed, the data stored in "sessionStorage" be permanently deleted.

Data is stored using key-value pairs.

SessionStorage syntax:


SessionStorage example:

If we stored for the user's session, the identifier of the shopping cart of the user, then run: