A strange problem occurs with http 200 from cache.

WBOY
Release: 2016-09-05 08:59:54
Original
1206 people have browsed it

Browser used: chrome on PC, various browsers on mobile phone
Visit the same url address: http://xxx.aaa.bbb.com/ship.html

In the test environment: Some students visited this address. When they visited again, the page still displayed the data from the last time they visited the page, which was not the latest data. Check its http, there are several important parameters as follows: 200, from cache. However, every time some students visit this address, the page shows the latest data. When checking several important http parameters, from cache does not appear.

from cache I understand, but what I don’t understand is why some students appear from cache when accessing the same server, while some students load the latest page data from the server when accessing. What does this have to do with, and what influences it?

Note:

  • In the official online environment, this problem does not exist, access is normal, and the latest page data is loaded from the server every time.

  • ship.html is not a straight static page, it is pseudo-static.

  • The following headers have been set:
    <meta http-equiv="Expires" content="-1">
    <meta http-equiv="Cache-Control" content="no-cache ">
    <meta http-equiv="Pragma" content="no-cache">

Reply content:

Browser used: chrome on PC, various browsers on mobile phone
Visit the same url address: http://xxx.aaa.bbb.com/ship.html

In the test environment: Some students visited this address. When they visited again, the page still displayed the data from the last time they visited the page, which was not the latest data. Check its http, there are several important parameters as follows: 200, from cache. However, every time some students visit this address, the page shows the latest data. When checking several important http parameters, from cache does not appear.

from cache I understand, but what I don’t understand is why some students appear from cache when accessing the same server, while some students load the latest page data from the server when accessing. What does this have to do with, and what influences it?

Note:

  • In the official online environment, this problem does not exist, access is normal, and the latest page data is loaded from the server every time.

  • ship.html is not a straight static page, it is pseudo-static.

  • The following headers have been set:
    <meta http-equiv="Expires" content="-1">
    <meta http-equiv="Cache-Control" content="no-cache ">
    <meta http-equiv="Pragma" content="no-cache">

If the server does not clearly define cache control, different clients may have different caching mechanisms.
If you want users to get the latest data every time, you can set the meta tag like this:

<code class="html"><meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" /></code>
Copy after login

Setting the meta tag is only effective for html pages. A better way is to set cache control in the http response header:

<code class="http">Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0</code>
Copy after login

php sets http response header code:

<code class="php">header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0"); // Proxies.</code>
Copy after login

Using caching can help speed up page loading and reduce resource consumption. You should adjust the caching strategy according to the specific situation.

Reference

http://stackoverflow.com/ques...
http://stackoverflow.com/ques...

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template