开发者

One question of browser cache mechanism

Image responses always consist of the "Last-Mo开发者_开发知识库dified" header. However, once I click F5 to refresh the page, IE always get the 304 response for these images rather than using local cahce.

Is it that clicking F5 always make browser issue a new request?

BTW: IIS is our host server (ASP.NET MVC 2).

Thanks.


The 304 response tells the browser that the image hasn't been modified since it was last downloaded. The browser then gets the image from its local cache.

Even though the image is cached locally, the browser still has to ask the server if there's an updated one to prevent the cache from getting stale.

EDIT:

When a page is loaded (or refreshed) in a browser, the browser looks for any needed files in its cache. If it finds a file in the cache, it looks at the time the cached file was created/modified.

The browser will then send a request to the server (even if there is a cached version of the file). In the request, the browser will include a header that has the created/modified time of the cached file. It is the responsibility of the server to compare the date sent in the header to the date the server's version was last changed. If the server finds that the client's cached version is old (i.e. the date sent by the browser is before the date of the server version), the server will just return the actual file and the browser will NOT use the cached version. The browser will update its cache with the new file.

If, on the other hand, the server copy was last modified before the cached file was created/modified, this means that the cached copy is still valid. The server will respond with an HTTP 304 code, which tells the browser that its cached copy is valid. The server will not resend the entire file in this case.

Oftentimes, a browser will not even bother to check for an updated file if it knows the cached copy is relatively recent (maybe only a few minutes or a few hours old). In this case, the browser will just use the cached copy without checking with the server for an updated version first. You can force the browser to ignore the cache by holding down control (or command on the Mac) while reloading the page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜