You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Matthew Claridge <mc...@rwa-net.co.uk> on 2006/06/06 10:30:08 UTC
[users@httpd] Image caching / Expiry times / 304s
Hi all,
I'm not sure if this is possible, because to me sending 304s is just
"how it all works"!.......however, my boss is looking for ways to
prevent a browser continually requesting images from our apache server -
these requests inevitably receive a 304 response and the thinking behind
this is that this is just a waste of resources on an already very busy
server.
We've looked into mod_expiry, but this doesn't really work, because as
soon as the expiry time is reached the browser starts requesting it
again and a new expiry is never set until the server actually sends the
image, so we can make this work with huge expiry times, but thats just
not practical as it means the images are never requested even if we've
changed them.
Anyone got any ideas?
cheers
Matt
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Image caching / Expiry times / 304s
Posted by Matthew Claridge <mc...@rwa-net.co.uk>.
on 06/06/2006 15:35 Joshua Slive said the following:
> On 6/6/06, Matthew Claridge <mc...@rwa-net.co.uk> wrote:
>
>>
>>
>> on 06/06/2006 15:16 Joshua Slive said the following:
>>
>> > On 6/6/06, Matthew Claridge <mc...@rwa-net.co.uk> wrote:
>> >
>> >> Apache does send a Cache-control header of "max-age=0", which if I'm
>> >> right means it isn't updatiing the expiry time?
>> >
>> >
>> > It means the content is marked as expired. What mod_expires config
>> > are you using?
>> >
>> > Joshua.
>>
>> <Location /images/>
>> <IfModule mod_expires.c>
>> ExpiresActive On
>> ExpiresByType image/jpg A432000
>> ExpiresByType image/jpeg A432000
>> ExpiresByType image/gif A432000
>> ExpiresByType image/png A432000
>> ExpiresByType image/ico A432000
>> </IfModule>
>> </Location>
>
>
> Seems like you have something else weird going on. The config used on
> www.apache.org is
> ExpiresActive On
> ExpiresDefault A86400
>
> And yet I get updated (non-zero) cache-control headers on 304 responses:
>
>> telnet www.apache.org 80
>
> Trying 192.87.106.226...
> Connected to www.apache.org.
> Escape character is '^]'.
> GET / HTTP/1.1
> Host: www.apache.org
> If-Modified-Since: Thu, 01 Jun 2006 14:07:19 GMT
>
> HTTP/1.1 304 Not Modified
> Date: Tue, 06 Jun 2006 14:31:19 GMT
> Server: Apache/2.2.0 (Unix) mod_ssl/2.2.0 OpenSSL/0.9.7g
> ETag: "20122-331e-4152a2fa513c0"
> Expires: Wed, 07 Jun 2006 14:31:19 GMT
> Cache-Control: max-age=86400
>
> So it looks like you have something else in your config that is
> resetting your cache-control headers.
>
> Joshua.
Looks like this is actually a bug in the 2.0 branch - we're using RHEL,
so we're stuck on the 2.0.46-x releases and this bug seems to have crept
in to an early 2.0 release and been fixed in 2.0.49
http://issues.apache.org/bugzilla/show_bug.cgi?id=25123
What a waste of time. Sorry. Thanks for your help though.
Matt
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Image caching / Expiry times / 304s
Posted by Matthew Claridge <mc...@rwa-net.co.uk>.
>
> Seems like you have something else weird going on. The config used on
> www.apache.org is
> ExpiresActive On
> ExpiresDefault A86400
>
> And yet I get updated (non-zero) cache-control headers on 304 responses:
>
>> telnet www.apache.org 80
>
> Trying 192.87.106.226...
> Connected to www.apache.org.
> Escape character is '^]'.
> GET / HTTP/1.1
> Host: www.apache.org
> If-Modified-Since: Thu, 01 Jun 2006 14:07:19 GMT
>
> HTTP/1.1 304 Not Modified
> Date: Tue, 06 Jun 2006 14:31:19 GMT
> Server: Apache/2.2.0 (Unix) mod_ssl/2.2.0 OpenSSL/0.9.7g
> ETag: "20122-331e-4152a2fa513c0"
> Expires: Wed, 07 Jun 2006 14:31:19 GMT
> Cache-Control: max-age=86400
>
> So it looks like you have something else in your config that is
> resetting your cache-control headers.
>
> Joshua.
Ok, there are two things going on here, one of which I'll hang my head
in shame for :-(
Firstly, the correct Cache-Control header is sent for the initial 200
response on these files - so what would prevent it from being sent only
on 304 responses?
Secondly, the /Cache-Control max-age=0/ header I mentioned earlier is in
the REQUEST header, not the server's response header! Seems I can't read
properly!
To clarify, these are the request and response headers for an initial
request for an image and then a subsequent request where the image is
cached:
Host=www.highandwild.co.uk
User-Agent=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4)
Gecko/20060508 Firefox/1.5.0.4
Accept=image/png,*/*;q=0.5
Accept-Language=en,en-us;q=0.5
Accept-Encoding=gzip,deflate
Accept-Charset=ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive=300
Connection=keep-alive
Referer=http://www.highandwild.co.uk/
Cookie=KMVisitor=10606061024500283146
Pragma=no-cache
Cache-Control=no-cache
Status=OK - 200
Date=Wed, 07 Jun 2006 08:10:57 GMT
Server=Apache/2.0.46 (Red Hat)
Last-Modified=Wed, 07 Jun 2006 08:05:00 GMT
Etag="85c0a2-f79-d2f28300"
Accept-Ranges=bytes
Content-Length=3961
Cache-Control=max-age=432000
Expires=Mon, 12 Jun 2006 08:10:57 GMT
Connection=close
Content-Type=image/jpeg
Host=www.highandwild.co.uk
User-Agent=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4)
Gecko/20060508 Firefox/1.5.0.4
Accept=image/png,*/*;q=0.5
Accept-Language=en,en-us;q=0.5
Accept-Encoding=gzip,deflate
Accept-Charset=ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive=300
Connection=keep-alive
Referer=http://www.highandwild.co.uk/
Cookie=KMVisitor=10606061024500283146
If-Modified-Since=Wed, 07 Jun 2006 08:05:00 GMT
If-None-Match="85c0a2-f79-d2f28300"
Cache-Control=max-age=0
Status=Not Modified - 304
Date=Wed, 07 Jun 2006 08:16:21 GMT
Server=Apache/2.0.46 (Red Hat)
Connection=close
Etag="85c0a2-f79-d2f28300"
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Image caching / Expiry times / 304s
Posted by Joshua Slive <jo...@slive.ca>.
On 6/6/06, Matthew Claridge <mc...@rwa-net.co.uk> wrote:
>
>
> on 06/06/2006 15:16 Joshua Slive said the following:
>
> > On 6/6/06, Matthew Claridge <mc...@rwa-net.co.uk> wrote:
> >
> >> Apache does send a Cache-control header of "max-age=0", which if I'm
> >> right means it isn't updatiing the expiry time?
> >
> >
> > It means the content is marked as expired. What mod_expires config
> > are you using?
> >
> > Joshua.
>
> <Location /images/>
> <IfModule mod_expires.c>
> ExpiresActive On
> ExpiresByType image/jpg A432000
> ExpiresByType image/jpeg A432000
> ExpiresByType image/gif A432000
> ExpiresByType image/png A432000
> ExpiresByType image/ico A432000
> </IfModule>
> </Location>
Seems like you have something else weird going on. The config used on
www.apache.org is
ExpiresActive On
ExpiresDefault A86400
And yet I get updated (non-zero) cache-control headers on 304 responses:
> telnet www.apache.org 80
Trying 192.87.106.226...
Connected to www.apache.org.
Escape character is '^]'.
GET / HTTP/1.1
Host: www.apache.org
If-Modified-Since: Thu, 01 Jun 2006 14:07:19 GMT
HTTP/1.1 304 Not Modified
Date: Tue, 06 Jun 2006 14:31:19 GMT
Server: Apache/2.2.0 (Unix) mod_ssl/2.2.0 OpenSSL/0.9.7g
ETag: "20122-331e-4152a2fa513c0"
Expires: Wed, 07 Jun 2006 14:31:19 GMT
Cache-Control: max-age=86400
So it looks like you have something else in your config that is
resetting your cache-control headers.
Joshua.
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Image caching / Expiry times / 304s
Posted by Matthew Claridge <mc...@rwa-net.co.uk>.
on 06/06/2006 15:16 Joshua Slive said the following:
> On 6/6/06, Matthew Claridge <mc...@rwa-net.co.uk> wrote:
>
>> Apache does send a Cache-control header of "max-age=0", which if I'm
>> right means it isn't updatiing the expiry time?
>
>
> It means the content is marked as expired. What mod_expires config
> are you using?
>
> Joshua.
<Location /images/>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg A432000
ExpiresByType image/jpeg A432000
ExpiresByType image/gif A432000
ExpiresByType image/png A432000
ExpiresByType image/ico A432000
</IfModule>
</Location>
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Image caching / Expiry times / 304s
Posted by Joshua Slive <jo...@slive.ca>.
On 6/6/06, Matthew Claridge <mc...@rwa-net.co.uk> wrote:
> Apache does send a Cache-control header of "max-age=0", which if I'm
> right means it isn't updatiing the expiry time?
It means the content is marked as expired. What mod_expires config
are you using?
Joshua.
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Image caching / Expiry times / 304s
Posted by Matthew Claridge <mc...@rwa-net.co.uk>.
on 06/06/2006 14:50 Joshua Slive said the following:
> On 6/6/06, Matthew Claridge <mc...@rwa-net.co.uk> wrote:
>
>>
>>
>> on 06/06/2006 14:30 Joshua Slive said the following:
>>
>> > On 6/6/06, Matthew Claridge <mc...@rwa-net.co.uk> wrote:
>
>
>> >> We've looked into mod_expiry, but this doesn't really work,
>> because as
>> >> soon as the expiry time is reached the browser starts requesting it
>> >> again and a new expiry is never set until the server actually
>> sends the
>> >> image, so we can make this work with huge expiry times, but thats
>> just
>> >> not practical as it means the images are never requested even if
>> we've
>> >> changed them.
>> >
>> >
>> > Two issues here:
>> >
>> > 1. The server should indeed be updating the Expires and Cache-Control
>> > headers even on 304 responses. See RFC2616 section 10.3.5. If it is
>> > not doing that, it is a bug. (It may also be a bug in the client that
>> > ignores the updated Cache-Control.)
>> >
>> > 2. A good practice is to set very-long expire (Cache-Control: max-age)
>> > headers on your images and then *never* change them. If you need to
>> > update the content, use a different filename. Of course, I believe
>> > most browsers and caches tend to ignore expiry dates more than a day
>> > or so in the future anyway.
>
>
>> Thanks for this. I originally thought your first point was correct and
>> that this was a bug. Certainly it was reported as a bug in version 1.1.1
>>
>> However, the docs for v2 state that once the expiry has passed, that
>> copy of the file is considered invalid and a new copy of the file MUST
>> be obtained from the server. This will of course never happen because
>> the server just sends 304s :-)
>
>
> The documentation you quote is just a general statement to help people
> understand how cache-control works. It is not an authoratative
> documentation on http caching rules. That is contained RFC2616. In
> this context, "a new copy" should also include a 304 response with an
> updated expiry time.
>
> Have you actually tested this? It should be easy enough to just make
> sure that apache is updating cache-control headers in 304 responses.
> No point arguing theoretically over something that is so easy to test.
>
Fair enough....I'm just reading it wrong :-)
Apache does send a Cache-control header of "max-age=0", which if I'm
right means it isn't updatiing the expiry time?
Matt
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Image caching / Expiry times / 304s
Posted by Joshua Slive <jo...@slive.ca>.
On 6/6/06, Matthew Claridge <mc...@rwa-net.co.uk> wrote:
>
>
> on 06/06/2006 14:30 Joshua Slive said the following:
>
> > On 6/6/06, Matthew Claridge <mc...@rwa-net.co.uk> wrote:
> >> We've looked into mod_expiry, but this doesn't really work, because as
> >> soon as the expiry time is reached the browser starts requesting it
> >> again and a new expiry is never set until the server actually sends the
> >> image, so we can make this work with huge expiry times, but thats just
> >> not practical as it means the images are never requested even if we've
> >> changed them.
> >
> >
> > Two issues here:
> >
> > 1. The server should indeed be updating the Expires and Cache-Control
> > headers even on 304 responses. See RFC2616 section 10.3.5. If it is
> > not doing that, it is a bug. (It may also be a bug in the client that
> > ignores the updated Cache-Control.)
> >
> > 2. A good practice is to set very-long expire (Cache-Control: max-age)
> > headers on your images and then *never* change them. If you need to
> > update the content, use a different filename. Of course, I believe
> > most browsers and caches tend to ignore expiry dates more than a day
> > or so in the future anyway.
> Thanks for this. I originally thought your first point was correct and
> that this was a bug. Certainly it was reported as a bug in version 1.1.1
>
> However, the docs for v2 state that once the expiry has passed, that
> copy of the file is considered invalid and a new copy of the file MUST
> be obtained from the server. This will of course never happen because
> the server just sends 304s :-)
The documentation you quote is just a general statement to help people
understand how cache-control works. It is not an authoratative
documentation on http caching rules. That is contained RFC2616. In
this context, "a new copy" should also include a 304 response with an
updated expiry time.
Have you actually tested this? It should be easy enough to just make
sure that apache is updating cache-control headers in 304 responses.
No point arguing theoretically over something that is so easy to test.
>
> Re your second point, if browsers ignore long expiry times anyway, then
> we are stuck with dealing with the 304 reponses, right?
Yes, I think you can expect at least one 304 a day from each client.
But that is just a guess. Again, testing is the way to go.
Joshua.
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Image caching / Expiry times / 304s
Posted by Matthew Claridge <mc...@rwa-net.co.uk>.
on 06/06/2006 14:30 Joshua Slive said the following:
> On 6/6/06, Matthew Claridge <mc...@rwa-net.co.uk> wrote:
>
>> Hi all,
>>
>> I'm not sure if this is possible, because to me sending 304s is just
>> "how it all works"!.......however, my boss is looking for ways to
>> prevent a browser continually requesting images from our apache server -
>> these requests inevitably receive a 304 response and the thinking behind
>> this is that this is just a waste of resources on an already very busy
>> server.
>>
>> We've looked into mod_expiry, but this doesn't really work, because as
>> soon as the expiry time is reached the browser starts requesting it
>> again and a new expiry is never set until the server actually sends the
>> image, so we can make this work with huge expiry times, but thats just
>> not practical as it means the images are never requested even if we've
>> changed them.
>
>
> Two issues here:
>
> 1. The server should indeed be updating the Expires and Cache-Control
> headers even on 304 responses. See RFC2616 section 10.3.5. If it is
> not doing that, it is a bug. (It may also be a bug in the client that
> ignores the updated Cache-Control.)
>
> 2. A good practice is to set very-long expire (Cache-Control: max-age)
> headers on your images and then *never* change them. If you need to
> update the content, use a different filename. Of course, I believe
> most browsers and caches tend to ignore expiry dates more than a day
> or so in the future anyway.
>
> Joshua.
>
Thanks for this. I originally thought your first point was correct and
that this was a bug. Certainly it was reported as a bug in version 1.1.1
However, the docs for v2 state that once the expiry has passed, that
copy of the file is considered invalid and a new copy of the file MUST
be obtained from the server. This will of course never happen because
the server just sends 304s :-)
Re your second point, if browsers ignore long expiry times anyway, then
we are stuck with dealing with the 304 reponses, right?
Matt
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Image caching / Expiry times / 304s
Posted by Joshua Slive <jo...@slive.ca>.
On 6/6/06, Matthew Claridge <mc...@rwa-net.co.uk> wrote:
> Hi all,
>
> I'm not sure if this is possible, because to me sending 304s is just
> "how it all works"!.......however, my boss is looking for ways to
> prevent a browser continually requesting images from our apache server -
> these requests inevitably receive a 304 response and the thinking behind
> this is that this is just a waste of resources on an already very busy
> server.
>
> We've looked into mod_expiry, but this doesn't really work, because as
> soon as the expiry time is reached the browser starts requesting it
> again and a new expiry is never set until the server actually sends the
> image, so we can make this work with huge expiry times, but thats just
> not practical as it means the images are never requested even if we've
> changed them.
Two issues here:
1. The server should indeed be updating the Expires and Cache-Control
headers even on 304 responses. See RFC2616 section 10.3.5. If it is
not doing that, it is a bug. (It may also be a bug in the client that
ignores the updated Cache-Control.)
2. A good practice is to set very-long expire (Cache-Control: max-age)
headers on your images and then *never* change them. If you need to
update the content, use a different filename. Of course, I believe
most browsers and caches tend to ignore expiry dates more than a day
or so in the future anyway.
Joshua.
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org