I have read several articles on the Internet recently, all of which are about HTTP. As the protocol that underwrites the entire Web application on the Internet, it must be difficult for developers to live without this knowledge. But then again, if I were to limit my career to a certain range of front-end engineers, how much HTTP knowledge do I really need to live a good life? This is a general overview of HTTP features, messages, caches, status codes, methods, cookies, cross-domain methods, persistent connections and piping, and what happens when the browser enters a URL to the page. What I can think of is still limited, but it is only to cast a brick to introduce jade. While recording my own thinking, I also hope to help others. Therefore, comments and exchanges are welcome.



HTTP features

When you think of HTTP, you definitely think of stateless, connectionless. How does a stateless website keep track of a user’s status? What’s a cookie for? Why shopping website searched mouse, a lot of websites can have small window to recommend mouse later? What is a three-way handshake? Multiple requests can be less than a few times? Of course, HTTP is flexible. How does it transfer different data types?

message

Packets are classified into request packets and response packets. Request message is divided into request line, request header, request body. Response packets are divided into response lines, response headers, and response bodies. So the question is, how do messages break lines? Is it the same as a newline in Linux? Where does the URL appear? What does the server use to parse the request message? Since the encoding of the body of a POST request is not specified, which encoding methods can be used?

The cache

Browser caches mainly include strong cache and negotiated cache. Why is it bad to just use Expires for strong caching? Is it not accurate to negotiate the cache only with last-Modified?

Status code

The common category of status codes is 12345. What’s the difference between 301 and 302? When do we have 304?

methods

HTTP methods include GET, POST, PUT, DELETE, and HEAD. So what’s the difference between GET and POST?

cookie

Cookies themselves are used for server-side and client-side communication and are borrowed because of their storage capabilities. So the question is, how do you set and retrieve cookies? What are the disadvantages of cookies? What are the advantages of localStorage and SessionStorage?

Cross-domain way

A simple summary of cross-domain can have the following several ways: hash, postMessage, json, CORS, Websocket, etc. So the question is, what are these cross-domain principles? What are the restrictions? Specific application scenarios?

Persistent connections and pipelining

Persistent connections require connection: keep-alive in the request header. So what are the requirements for HTTP versions of long connections? What is pipelining? What is the process of requesting a response? What do you need to pay attention to in pipelining?

What happens when the browser enters the URL to the page and displays it

The ultimate question is, what happens when the user types “www.baidu.com” from the browser until the page is rendered? To simplify the problem, how does the client initiate the request? How does the server respond to requests? How does the client parse the HTML and render the page? And what is rearranging and redrawing? When did it happen? How to avoid it?

Conclusion:

HTTP can be a lot of content in a single column. These are just the basics, but it’s easier to master them as a front-end engineer. As we accumulate knowledge and practical experience, the boundaries of the technology will expand and more of the mysteries of HTTP will be discovered. In short, a lot of things you didn’t know.

Reference links:

Developer.mozilla.org/zh-CN/docs/… Imququ.com/post/four-w…