Cookies and web Storage of data storage.

Source: Internet
Author: User
Tags sessionstorage

Cookies

Cookies, sometimes in their plural form, are the data (usually encrypted) stored on the user's local terminal by certain websites in order to identify the user and track the session. The next step is to talk about some of the advantages and disadvantages of cookies, cookie although the persistent preservation of client data provides the convenience of sharing the burden of server storage, but there are many limitations.

First: Generate up to 20 per specific domain namecookie。

1.IE6或更低版本最多20个cookie2.IE7和之后的版本最后可以有50个cookie。3.Firefox最多50个cookie4.chrome和Safari没有做硬性限制

第二:IEAnd Opera will clean up the least recently used cookie , Firefox will be randomly cleaned cookie .

第三:cookieThe maximum is approximately 4096 bytes (4KB), and for compatibility, it is generally not possible to exceed 4095 bytes.

IE provides a kind of storage that can persist user data, called userdata , from the IE5.0 start support. Each data is up to 128K, up to 1M under each domain name. This persisted data is placed in the cache and will persist if the cache is not cleaned up.

Benefits: Very high scalability and availability
1.通过良好的编程,控制保存在cookie中的session对象的大小。2.通过加密和安全传输技术(SSL),减少cookie被破解的可能性。3.只在cookie中存放不敏感数据,即使被盗也不会有重大损失。4.控制cookie的生命期,使之不会永远有效。偷盗者很可能拿到一个过期的cookie。
Disadvantages:

1.Cookie数量和长度的限制。每个domain最多只能有20条cookie,每个cookie长度不能超过4KB,否则会被截掉。

2.安全性问题。如果cookie被人拦截了,那人就可以取得所有的session信息。即使加密也与事无补,因为拦截者并不需要知道cookie的意义,他只要原样转发cookie就可以达到目的了。

3.有些状态不可能保存在客户端。例如,为了防止重复提交表单,我们需要在服务器端保存一个计数器。如果我们把这个计数器保存在客户端,那么它起不到任何作用。

Web Storage: Browser local Storage

In the higher version of the browser, a js sessionStorage and globalStorage . Provided in the HTML5 localStorage to replace globalStorage .

html5Web Storagetwo types of storage are included: sessionStorage and localStorage .

sessionStorage用于本地存储一个会话(session)中的数据,这些数据只有在同一个会话中的页面才能访问并且当会话结束后数据也随之销毁。因此sessionStorage不是一种持久化的本地存储,仅仅是会话级别的存储。
localStorage用于持久化的本地存储,除非主动删除数据,否则数据是永远不会过期的。

The difference between Web storage and cookies

Web StorageThe concept and cookie similarity, the difference is that it is designed for larger capacity storage. Cookiethe size is limited, and every time you request a new page Cookie will be sent in the past, this virtually wasted bandwidth, you cookie also need to specify the scope, not cross-domain calls.

In addition, Web Storage having setItem,getItem,removeItem,clear such methods does not cookie need to be packaged by front-end developers themselves setCookie,getCookie . But it is cookie also not possible or missing: cookie The role is to interact with the server, as HTTP part of the specification exists, but Web Storage only for the local "storage" of data.

Browser support In addition IE7 to the following is not supported, other standard browser is fully supported (IE and FF need to run in the Web server), it is worth mentioning that IE always do good things, such as IE7, IE6 in userData fact, is the solution of javascript local storage. Through simple code encapsulation can be unified to all browsers are supported web storage .

localStorageAnd sessionStorage both have the same methods of operation, such as setItem、getItem and removeItem so on.

The difference between a cookie and a session:

1、cookie数据存放在客户的浏览器上,session数据放在服务器上。

2、cookie不是很安全,别人可以分析存放在本地的COOKIE并进行COOKIE欺骗 考虑到安全应当使用session。

3、session会在一定时间内保存在服务器上。当访问增多,会比较占用你服务器的性能 考虑到减轻服务器性能方面,应当使用COOKIE。

4、单个cookie保存的数据不能超过4K,很多浏览器都限制一个站点最多保存20个cookie。

5、所以个人建议: 将登陆信息等重要信息存放为SESSION 其他信息如果需要保留,可以放在COOKIE中。

Cookies and web Storage of data 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.