1

When looking at the network waterfall in Firebug/Chrome/IE9, I keep seeing "200-OK" instead of "304-Not Modified" for many cache-able files (images, js, css) on this page, for example.

I believe it is because the browser is not sending a If-Modified-Since during the Request, right? Do I need to change something in the initial Response headers to make 304s happen?

FF13 screenshot

2

I believe it is because the browser is not sending a If-Modified-Since during the Request, right?

Correct.

Do I need to change something in the initial Response headers to make 304s happen?

Yes. If you compare original response headers for those resources that have 304 response code on subsequent requests, you will notice:

  1. All of them located in /govtrip/site/grphx/ folder
  2. They have "Etag", "Expires" and "Last-Modified" headers

The first moment tells that most likely there is .htaccess file in that folder that sets those headers (or separate section elsewhere in config file for that folder).

If you look at request headers for those resources with 304 response code, you will see the presence of "If-Modified-Since" and "If-None-Match" headers. Based on those "If-*" headers Apache decides how to reply to the request. I'm sure -- now you can see a pattern here -- very easy to spot which values where used and where.

Resource: /govtrip/site/grphx/system_green.gif

Original response:

Etag: "AAAAS9z9eMo"
Expires: Thu, 14 Jun 2012 18:24:24 GMT
Last-Modified: Wed, 20 Apr 2011 17:29:45 GMT

Subsequent request:

If-Modified-Since: Wed, 20 Apr 2011 17:29:45 GMT
If-None-Match: "AAAAS9z9eMo"
|improve this answer|||||
  • That's what I was thinking also, but was not sure if sending Expires and Last-Modified was the only thing necessary. Does an Etag need to be sent, or will 304s happen without it? – utt73 Jun 12 '12 at 20:14
  • 1
    Well .. general practice is to remove ETag to save a bit on bandwidth if other possible "If-*" header is present (which is the case in your example). 1) en.wikipedia.org/wiki/HTTP_ETag 2) webmasters.stackexchange.com/search?q=etag – LazyOne Jun 12 '12 at 20:21
0

In my experience, browsers never use the If-Modified-Since header. I've only seen it sent by crawlers, such as Googlebot. To elicit conditional downloads, answer with ETag: hash-here first, then watch out for If-None-Match: hash-here in consequent requests for the same URL. Cache must expire first before a conditional download is issued, so make sure you use proper immediately-expiring headers.

Note: There is also a If-Match header. This one is used only with partial downloads and prevents corruption by letting you detect that the file has changed and resuming is no longer possible. In advanced situations, it can even let you pick the file to resume from.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.