Home > Article > Web Front-end > A brief introduction to HTTP caching mechanism
This article brings you a brief introduction to the HTTP caching mechanism. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
HTTP caching mechanism
HTTP caching is divided into two types: forced caching and comparative caching
Before we understand these, let’s briefly understand the HTTP message. The HTTP message is the browser and The data sent and responded to during server communication is fast.
Request header header Additional information (cookie, cache information, etc.) and cache-related rule information are included in the header
And the request body body The part that the HTTP request really wants to transmit
After briefly understanding these, let’s take a look at strong cache and contrast cache
Strong cache keyword expires cache-control max-age = set the expiration time and compare the last-modified record in the cache keyword response header Last request time
request header if-modified-since is compared with the last request time.
etag records the unique identifier if-none-match compares with etag to see if it is consistent and returns to the server to return the unique identifier
You can get the cached data status code 304
How to set up the request cache
The front-end sets http cache and the front-end sets html page cache method: If you want to set up cache for static html pages, you need to set expires and cache-control through HTTP META
Set the following web page meta information:
<meta http-equiv="Cache-Control" content="max-age=7200" /> <meta http-equiv="Expires" content="Mon, 20 Jul 2013 23:00:00 GMT" />
This article is all over here. For more exciting content, you can pay attention to the JavaScript Tutorial Video column on the PHP Chinese website!
The above is the detailed content of A brief introduction to HTTP caching mechanism. For more information, please follow other related articles on the PHP Chinese website!