开发者

How can I force browsers to not re-request a resource on refresh?

I'm trying to force the browser to cache different resources like CSS, images, js and so on forever. It is impor开发者_C百科tant for the browser to never try to refresh the images/css since on a page there might be thousands of small images, and when the browser tries to refresh it bombards the server, and needlessly keeps the page in refresh mode. The images/css's never change nless the request path changes.

Right now I have the path to the images/css set to a script with a url like:

"http://example.com/img/get.php?n=someimage.jpg&v=7"

and the script is sending these headers before sending the resource:

header("Cache-Control: public");
header("Expires: Tue, 19 Jan 2037 00:00:00 GMT");
header("Last-Modified: Sat, 01 Jan 2000 00:00:00 GMT");

However Chrome and Firefox both re-request the image/css if the Refresh button is hit. Chrome also seems to send the request if you hit Enter on the address bar, unlike Firefox.

My question is why do they do this since the Expires header should make it not do the request again until 2037, even if the users presses Refresh. Am I doing something wrong, or missing something?


You can't. As you've noticed, some browsers take the definition of "refresh" to mean "refresh and refresh the cache to".

Servers can only offer guidance to web browsers on caching, they can't enforce it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜