Jump to content

Will images cache when called absolutely?


TheFilmGod

Recommended Posts

There are a number of different headers you could use.

 

For instance, if you would like it cached for one month then you could do Expires: Tue, 22 Jul 2008 20:42:40 GMT and Cache-Control: max-age=2592000; must-revalidate (one month being 30 days here). Furthermore, keeping Last-Modified accurate and sending an ETag will also help. An ETag is simply, well... a tag. It changes each time the file changes and the client can then check by sending the ETag in a If-None-Match request header. If the ETag matches then the server will send an HTTP 304 Not Modified response header and the browser will then use the cached version instead. If I remember correctly, then ETags where introduced in HTTP 1.1.

 

A combination of the above might be the ideal solution.

On a static HTML file on my VPS I received the following response headers:

 

HTTP/1.1 200 OK
Date: Sun, 22 Jun 2008 21:53:36 GMT
Server: Apache/2.2.3 (Debian) DAV/2 SVN/1.4.2 PHP/5.2.0-8+etch11 mod_ssl/2.2.3 OpenSSL/0.9.8c
Last-Modified: Thu, 19 Jun 2008 09:44:58 GMT
ETag: "7a8aec-21a-d48c5a80"
Accept-Ranges: bytes
Content-Length: 538
Content-Type: text/html; charset=UTF-8

 

Note that the Last-Modified header was set to when I actually last modified it. Apache determines this by the last change time of the file.

I have one last question -

 

What about dynamically generated files, like php? Do I need to amend the headers sent to ensure that the files aren't cached? Or will apache notice the difference between the static/dynamic files?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.