During an interview, the interviewer asked me a series of questions about browser cookies, including cookie size, cookie count restrictions, and how to operate cookies. To be honest, I seldom pay attention to this issue and use cookies during the usual JS usage process. So this time I was stunned and couldn't say anything, finally, I can only honestly tell you that I am not very familiar with the operations on this cookie. Today, some colleagues asked questions about cookies. I went to the Internet and made some summary records for use from time to time. Cookie operations should be relatively familiar to JS programmers, so they will not be explained too much.
The following are the different cookie restrictions on different browsers:
|
IE6.0 |
IE7.0/8.0 |
Opera |
FF |
Safari |
Chrome |
Cookie count: |
Each domain has 20 |
50 for each domain |
Each domain has 30 |
50 for each domain |
No quantity limit |
Each domain has 53 |
Total cookie size: |
4095 bytes |
4095 bytes |
4096 bytes |
4097 bytes |
4097 bytes |
4097 bytes |
After the number limit is exceeded:
1. The processing of IE and Opera is the same. They all use the "least recently used algorithm". When the cookie has reached the limit, the oldest cookie will be automatically removed to leave available space for the newest cookie.
2. FF is very special. Although the last cookie is retained, it seems that there is no rule to delete the existing cookie randomly.
Note:
When we perform page cookie operations, we should try to ensure the number of cookies and the corresponding size. Best cookie count <20 ~ 30; the best cookie size <4 K