HTML 5 Web storage and htmlweb Storage
Store data on the client
HTML5 provides two new methods to store data on the client:
- LocalStorage-data storage with no time limit
- SessionStorage-data storage for a session
Previously, these are all completed by cookies. However, cookies are not suitable for storing a large amount of data because they are transmitted by each request to the server, which makes the cookie speed slow and inefficient.
In HTML5, data is transmitted not by each server request, but only by the request. It makes it possible to store a large amount of data without affecting the website performance.
For different websites, data is stored in different regions, and a website can only access its own data.
HTML5 uses JavaScript to store and access data.
LocalStorage Method
There is no time limit on the data stored by the localStorage method. Data is still available on the second day, the second week, or after the next year.
How to create and access localStorage:
<!DOCTYPE HTML>
The following example calculates the number of times a user accesses a page:
<! Doctype html>
SessionStorage Method
The sessionStorage method stores data for a session. When the user closes the browser window, the data will be deleted.
How to create and access a sessionStorage:
<!DOCTYPE HTML>
The following example calculates the number of times a user accesses a page in the current session:
<! Doctype html>