We can use the header to control the HTML page using the META tag and PHP program. For example:
The code is as follows
Header (' cache-control:max-age=86400, Must-revalidate ');//24 hours
Header (' last-modified: '. Gmdate (' d, D M Y h:i:s '). ' GMT ');
Header (' Expires: '. Gmdate (' d, D M Y h:i:s ', time () + ' 86400 '). ' GMT ');
Echo ' I don't refresh '; write an HTML file c.htm:
Haha,go
We request 127.1/c.htm, click on the link, and then take advantage of the browser's fallback button, Back to C.htm, and then click on the link, as shown in the left, we found that when the cache instruction is added, we back and click the link anyway, the following network request URL This line is always gray, indicating that the browser does not initiate the actual network request, but instead directly calls the cached page stored in the user's computer, unless the cache time expires, Even if the actual content changes, the browser will not be able to re-read our resources on the server. You can change the echo of the sentence, and then click, you will find that the network request is still gray. In this case, only the following three scenarios are available for the browser to update the cache:
(1) Cache expiration
(2) the cache is cleared;
(3) F5 or Ctrl+f5 forced refresh. (There may be differences in various browser processing, my test environment is Firefox 4)
The HTTP 1.1 protocol is used when we block the header command above or use the following code to tell the client that the browser is not using the cache.
The code is as follows
Header ("Cache-control:no-cache, must-revalidate");
Tells the client browser not to use the cache, compatible with the HTTP 1.0 protocol
The code is as follows
Header ("Pragma:no-cache");
The browser will go to the server to read the resources on each request. The image to the right of the following faces is shown. Here, we can understand the browser to the page cache processing. It's easy for us to think about its usage scenarios, sometimes we need it to cache, and sometimes we don't need it, and you can use it based on the scene. However, the browser's caching role is very small, but can save a little bit. Sometimes, the browser cache is very powerful, we need to force the refresh to take effect, such as JS file, sometimes you change, even if the refresh will not change. In addition, you can set the page cache in code, you can also configure on servers such as Apache, especially static resources, plus caching can effectively reduce unnecessary requests.
And sometimes, we usually see this code, after the JS file with a question mark of the string does not make sense, just to avoid JS is cached, add a version to the JS file, usually tagged with a timestamp. This way the browser will not cache our JS files.
Since the purpose of the front-end page cache is to reduce the request, I immediately think of another idea, that is, compressing the data. By using some tools, you can compress CSS and JS code. For example, the use of jquery version is compressed, often this compression ratio is still very large. Compression is usually done using Jsmin,jspacker, and the tools can be searched online.
http://www.bkjia.com/PHPjc/371798.html www.bkjia.com true http://www.bkjia.com/PHPjc/371798.html techarticle we can use the header to control the HTML page using the META tag and PHP program. For example: The code follows the header (' cache-control:max-age=86400, Must-revalidate ');//24 hours Header (' Last-mo ...