Home  >  Article  >  Web Front-end  >  I want to ask for advice on the HTTP caching problem! Please help! _html/css_WEB-ITnose

I want to ask for advice on the HTTP caching problem! Please help! _html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:10:001075browse

<h1>aa</h1><img src="1.jpg" width="100" /><img src="2.jpg" width="100" />


1.
In order to verify whether reading this page is from the cache, I do the following:
Open this page normally for the first time. Then for the second time, press Enter in the address bar (not refresh)
I used httpwatch in IE to see that the file was indeed read from the cache, and no HTTP request was sent to the server


I used FireBug under FireFox to see that the file should also be read from the cache, because this page has only one HTTP request (the first time was 3). This request contains HTTP request headers and corresponding headers.
But my question is, why does it still initiate this request? Shouldn't the file be read directly from local?


2.
In order to disable caching for this file, I made the following settings:
Expires: -1
Cache-Control: no-cache
pragma: no -cache

Looking with IE, it is true that the file is not read from the cache, but an HTTP request is initiated and 200 is returned. But my question is, if this file is not read from the cache, then the browser should send three requests to the server, right? Even if the image is cached, you should initiate a request and return the 304 code before reading it locally. Why is it only initiated once? ? ?


3.
How long do browsers generally cache by default? How to set it in HTTP response header information?


I am a newbie~ It is not easy to answer so many questions. I would also like to ask all the experts to read my questions carefully. Thank you very much! ! !


Reply to discussion (solution)

Sending a request to the server is to confirm whether the latest cache is available.

Sending a request to the server is to confirm whether the latest cache is available.
Are you answering my first question?
Then why when I use httpwatch to view it under IE, no request is initiated, and even if I change the page code and press Enter to view it, it still looks like it has not been changed, indicating that it has not confirmed whether the cache is the latest available.
It seems that only when requesting a picture or something, you can check whether the cache is the latest, but the page cache does not check.

You can pass a time parameter when requesting so that you can skip the browser cache

Host, do you think there is no http after caching? Of course this is impossible, it must access the server, but at this time the page content is not returned from the server, but the server tells the browser that you use your own cache, so. .

Owner, do you think there won’t even be an http after caching? Of course this is impossible, it must access the server, but at this time the page content is not returned from the server, but the server tells the browser that you use your own cache, so. .
But using IE's httpwatch to capture packets, it is a cache that is read directly without sending any information to the server. It should only send a request to cache images or something, and then determine whether the last update time is the same as that on the server. The page should not be used.

The browser will send the last update time information of the cache to the server. Whether the cache is available should be returned to the browser by the server.

The browser will send the last update time information of the cache to the server. Whether the cache is available should be returned to the browser by the server.
First of all, thank you for answering my question~ But please read my question carefully. . . As I said above, I'm asking about page caching, not pictures or anything like that. The request initiated when this page was cached did not have the "If-Modified-Since" parameter at all, so it did not match the last modification time with the server.

Please read my question carefully, thank you! Thank you! ! !

Can anyone help?

Statement:
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