The pros and cons of cookies and the difference from Web Storage

Source: Internet
Author: User
Tags sessionstorage

Benefits of Cookies: Very high scalability and availability

    1. Control the size of the session object saved in the cookie through good programming.
    2. Reduce the likelihood of cookies being cracked through encryption and secure transfer technology.
    3. Only sensitive data is stored in cookies, and there is no significant loss even if it is stolen.
    4. Control the life of a cookie so that it does not work forever. In this case, the thief is likely to get an expired cookie.

Disadvantages of Cookies:

    1. Limits on the length and number of cookies. There can be up to 20 cookies per domain, and each cookie cannot exceed 4KB in length. Otherwise it will be cut off.
    2. Security issues. If a cookie is blocked, the person can get all the session information. Encryption doesn't work.
    3. Some states cannot be saved on the client. For example, to prevent a duplicate submission of a form, we need to save a counter on the server side. If the counter is stored on the client, it does not play any role.

Web Storage in HTML5 includes two ways to store: Sessionstorage and Localstorage

sessionstorage is used to store data locally in a session, which can only be accessed by a page in the same session and destroyed when the session ends. So sessionstorage is not a persistent local store, only session-level storage.

While Localstorage is used for persistent local storage, data is never available until the data is actively deleted.

The concept of Web storage is similar to a cookie, except that it is designed for larger capacity storage. Cookie size is limited, and every time a new page is requested, the cookie is sent in the past, and the cookie needs to specify the scope and cannot be called across domains.

The role of cookies is to interact with the server as part of the HTTP specification, whereas Web Storage are only intended to store data locally.

Both Localstorage and Sessionstrage have the same methods of operation, such as Setitem,getitem and RemoveItem.

The pros and cons of cookies and the difference from Web Storage

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.