HTML5 local storage-What if there is no database? _ html5 tutorial skills-

Source: Internet
Author: User
Tags sessionstorage
This chapter mainly covers WebStorage and local databases. Among them, WebStorage is the optimization of cookies. The local database is a new function of HTML5. using it, you can create a database on the client, which greatly reduces the burden on the server, accelerate Data Access Preface

This chapter mainly covers Web Storage and local databases, where Web Storage optimizes cookies. Local databases are a new function of HTML5. You can use this function to create a database on the client.

This greatly reduces the burden on the server and accelerates data access.

To learn this chapter, you must master the basic concepts of Web Storage and understand the usage and differences between sessionStorage and localStorage.

Master the use of local databases

What is WebStorage?

As mentioned above, webstorage is optimized for cookies. In HTML4, cookies are used to store user data on the client. The following problems have been found during long-term use:

The size limit is 4 kbcookie, which is sent along with the HTTP transaction each time. It is complicated to waste bandwidth to operate the cookie correctly (this should be considered)

Due to the above problems, HTML5 proposed WebStorage as a new local storage technology for the client.

The Code is as follows:


The Web Storage technology stores data locally on the web Client. Specifically, it can be divided into two types:
SessionStrage:
Session refers to the period from the time when a user browses a website to the time when the user closes the website, the validity period of the session object is only so long.

LocalStorage:
Save the data on the client hardware device, no matter what it is, that is, the data is still in the next time you open the computer.

The difference between the two is temporary storage and long-term storage.


Example

The Code is as follows:


Simple Application







Web Storage experiment




SessionStorage LocalStorage

Save data

Read data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.