The difference between HTML5 Web Storage and cookies

Source: Internet
Author: User
Tags sessionstorage

The following comparisons are made from 3 aspects: 1, Capacity: Cookies are only 4kb,localstorage and sessionstorage maximum capacity 5m2, will be carried into Ajax: Cookies are transmitted by each request to the server, which can affect the efficiency of acquiring resources, Localstorage and Sessionstorage only use the data when requested. It makes it possible to store large amounts of data without compromising site performance. 3,api Ease of Use: cookies require encapsulation to be used, localstorage and sessionstorage are easy

HTML5 is designed for storage and provides two new ways to store data on the client: Localstorage and Sessionstorage

    • Localstorage-Data storage with no time limit, data is still available after the next day, the second week, or the next year.
    • Sessionstorage-Data storage for a session, when the user closes the browser window, it is deleted.
A maximum capacity of 5M, data is not passed by each server request, but only when the data is used on request. It makes it possible to store large amounts of data without compromising site performance.

For different sites, the data is stored in different regions, and a Web site can only access its own data.

HTML5 uses JavaScript to store and access data.

API easy to use Localstorage.setitem (key,value) Localstorage.getitem (key) Note: iOS Safari Stealth mode (privacy mode) Localstorage and Sessionstroage will be error recommended unified use of the Try-catch encapsulation cookie itself for client and server communication but it has local storage capabilities, so it is "borrowed"   Cookies are used to store the disadvantage of storage is too small, only 4KB all HTTP requests are carried, will affect the efficiency of obtaining resources API needs encapsulation to use Document.cookie = ... Refer to other links for details: https://www.cnblogs.com/kaixin3946/p/6042014.html

The difference between HTML5 Web Storage and cookies

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.