开发者

How to make HTTP Cache Headers Work

开发者 https://www.devze.com 2023-01-09 02:41 出处:网络
Can someone please help me with a HTTP caching question? I thought that if I set the \"Expires\" and \"Cache-Control:max-age\" request headers, then a browser wouldn\'t make a GET request until after

Can someone please help me with a HTTP caching question?

I thought that if I set the "Expires" and "Cache-Control:max-age" request headers, then a browser wouldn't make a GET request until after the max-age had passed?

My server is seeing lots of conditional GET requests, and it replies with a 304. However, I'd like to eliminate these conditional GETs if possible and have the browser only ask for a resource once it thinks it has expired.

Here's the details I get from the developer tools in Chrome:

Request URL:http://localhost:8080/img/branding.gif
Request Method:GET
Status Code:304 Not Modified

Request Headers:

Cache-Control:max-age=0
If-Modified-Since:Thu, 22 Jul 2010 10:54:34 GMT
Referer:http://localhost:8080/
User-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4

Response Headers:

Cache-Control:max-age=2246400, s-maxage=0
Connection:Keep-Alive
Content-Location:/开发者_StackOverflow中文版img/branding.gif
Content-Type:image/gif
Date:Fri, 23 Jul 2010 15:06:10 GMT
Expires:Fri, 07 Jan 2011 15:06:10 GMT
Keep-Alive:timeout=15, max=100
Last-Modified:Thu, 22 Jul 2010 10:54:34 GMT
Pragma:cache
Server:Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)

I set the cache headers in a filter in my Java code. The code is running on Oracle's OC4J.

Also, I want to run this over HTTPS. Will using the same headers work for HTTPS too?

Thanks in advance.


Remove "Last-Modified" header. Some browsers always send conditional GET if that header exists.


Could it be the s-maxage=0? Can you lose that, or set it the same as the maxage?

The conditional gets could be coming from proxies, or from browsers that have somehow decided to act like proxies. Seems unlikely, i admit.

0

精彩评论

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