Sessionstorage && localstorage && Cookies

Source: Internet
Author: User
Tags sessionstorage

    • The Localstorage life cycle is permanent, which means that the information will always be present unless the user is shown to clear Localstorage information on the UI provided by the browser.

      The Sessionstorage life cycle is the current window or tab, and once the window or tab is permanently closed, all data stored through sessionstorage is emptied.

    • The information in Localstorage or sessionstorage cannot be shared by different browsers. The same localstorage can be shared between different pages in the same browser (the page belongs to the same domain name and port), but sessionstorage information cannot be shared between pages or tabs. It is important to note that pages and tabs refer only to top-level windows, and if a tab contains multiple IFRAME tags and they belong to the same-origin page, they can be shared sessionstorage.

    • The contents of the cookie mainly include: name, value, expiration time, path and domain. The path together with the domain constitutes the scope of the cookie. If you do not set an expiration time, this indicates that the

The lifetime of a cookie is a browser session, and the cookie disappears when you close the browser window. This cookie, which is the lifetime of the browser session, is referred to as a session cookie.

Session cookies are generally not stored on the hard disk but are kept in memory, although this behavior is not regulated. If the expiration time is set, the browser will place the cookie

Save to the hard disk, turn off the browser again, and these cookies remain valid until the set expiration time is exceeded. Cookies stored on the hard disk can be used in different

Browser process, such as two IE windows. For cookies stored in memory, different browsers have different ways of handling them.

In fact, this technique can be replaced simply by applying URL rewriting to the action.

The difference between a cookie and a session:

1. The cookie data is stored on the client's browser and the session data is placed on the server.

2, the cookie is not very safe, others can analyze the cookie stored in the local and cookie deception
Consider that security should use the session.

3. Session will be saved on the server for a certain period of time. When access is increased, it will be more likely to occupy your server's performance
The cookie should be used in consideration of mitigating server performance.

4, a single cookie can not save more than 4K of data, many browsers restrict a site to save up to 20 cookies.

5, so personal advice:
Storing important information such as login information as session
Additional information can be placed in a cookie if it needs to be retained

http://adamed.iteye.com/blog/1698740

Http://www.cnblogs.com/shiyangxt/archive/2008/10/07/1305506.html

Sessionstorage && localstorage && 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.