This is the 19th day of my participation in Gwen Challenge.

Star: github.com/Jackson0714… Personal website: www.passjava.cn

Common Interview questions

1. What is Cookie? U do

2. What can cookies do? U do

3. How are cookies classified? U do

4. How does Cookie work? U u u

5. How are cookies stored? U do

6. Do I send all cookies to all sites every time I visit the site? u

7. How to choose between cookie and cache? End to end

8. Disadvantages of cookies? End to end

9. How do I use cookies? U u u

After reading these topics, whether there is doubt in the heart? Well, keep reading, and I’ll help you answer your questions

Refer to the answer

1. What is Cookie? U do

Cookies are the best way to recognize the current user and implement a persistent session. To put it simply, the server knows which clients it is communicating with and keeps communicating with the identified clients. The basic idea behind cookies is that the browser accumulates a set of server-specific information that is presented to it each time it visits the server.

2. What can cookies do? U do

You know more about the user on the other end of the connection and can track them as they browse the page.

3. How are cookies classified? U do

(1) Session cookie. Temporary cookies, which record a user’s Settings and preferences when visiting a site. The session cookie is deleted when the user exits the browser.

(2) Persistent cookies. Persistent cookies live longer; They are stored on the hard disk, the browser exits and the computer restarts. Persistent cookies are typically used to maintain a profile or login name for a site that a user will visit periodically.

The only difference is when they expire. If Discard is set, Expires is not set, or max-age is not set, the cookie is a session cookie.

4. How does Cookie work? U u u

(1) When a user visits a Web site for the first time, the Web server knows nothing about the user.

(2) The Web server stores cookies in the Cookie database in the browser through the set-cookie initial. The cookie contains N key-value pairs, for example, cookie: ID = 1234. Cookies can contain any information, but they usually contain only a unique identifier generated by a server for tracking purposes.

(3) When the user visits the same site again in the future, the browser will select the cookie set by the server from the cookie database and send it back to the server in the cookie request header (cookie: ID = “1234”).

(4) The server can use the key-value pair id=”1234″ to find the information (shopping history, address information, etc.) that the server has accumulated for its access.

Note: Cookies are not limited to ID numbers. Many Web servers store information directly in Cooki. For example Cookie: name=”Tom”; phone=”111-2222″

5. How are cookies stored? U do

Browsers are responsible for storing cookie information. Different browsers store cookies in different ways. Some browsers use cookis.txt for storage. Some browsers are stored in separate text files in a cache directory.

6. Do I send all cookies to all sites every time I visit the site? u

No, browsers usually only send 2 or 3 cookies per site. Here’s why:

(1) Transferring all these cookie bytes severely degrades performance.

(2) Cookies contain server-specific name-value pairs. For most sites, most cookies are useless data that cannot be recognized.

(3) Sending all cookies to all sites raises potential privacy issues, as sites you don’t trust get information you only want to send to other sites.

7. How to choose between cookie and cache? End to end

Cookies are private, and browsers do not want to get the same cookies as other browsers. Cookie images are generally cached, not text.

8. Disadvantages of cookies? End to end

Security risks exist. One of the biggest abuses of cookies is the use of persistent cookies by third-party Web sites to track users. By combining this with IP addresses and Referer headers, marketing companies can build up fairly accurate profiles and browsing patterns.

9. How do I use cookies? U u u

The Cookie header is used in the request sent by the browser. It sends all unexpired cookies that match the domain, path, and security filters to the site. All cookies are grouped into a cookie header.

Cookie: Name1=Tom; Name2=Jerry

Welcome to follow my official account: “Wukong Chat Framework”

About the author: 8-year Veteran of Internet workplace | full stack engineer | super dad after 90 | open source practitioner | owner of public number 10,000 fans original number. Blue Bridge signed the author, the author of “JVM performance tuning practice” column, handwritten a set of 70,000 words SpringCloud practice summary and 30,000 words distributed algorithm summary. Welcome to follow my public account “Wukong Chat framework”, free access to learning materials.

I am Wukong, strive to become stronger, become super Saiya people!