HTTP question - file that never changes

J

Jim Higson

I couldn't find an alt.http. Ah well...

I'm working on a server app, which makes resources with the creation time in
the URL, so they are guarantied never to change once put up.

Because the resource for a given URL never changes, browser cache is always
safe to use and there is no need to revalidate. What are the best HTTP
header(s) to use to indicate this, and how should they be set in Apache?
 
R

Roy Schestowitz

__/ [ Jim Higson ] on Wednesday 08 March 2006 11:51 \__
I couldn't find an alt.http. Ah well...

I'm working on a server app, which makes resources with the creation time
in the URL, so they are guarantied never to change once put up.

Because the resource for a given URL never changes, browser cache is always
safe to use and there is no need to revalidate. What are the best HTTP
header(s) to use to indicate this, and how should they be set in Apache?

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

See Section 14.9

To prevent caching, for example, HTTP headers or HTML headers should contain

,----[ Code ]
| Pragma: no-cache
| Cache-Control: no-cache
`----

Also see: http://www.i18nguy.com/markup/metatags.html

Apache specifics at: comp.infosystems.www.servers.unix

To debug, use Firefox with the Live Headers extension.

Hope it helps,

Roy
 
A

Alan J. Flavell

I'm working on a server app, which makes resources with the creation
time in the URL, so they are guarantied never to change once put up.

Because the resource for a given URL never changes, browser cache is
always safe to use and there is no need to revalidate. What are the
best HTTP header(s) to use to indicate this, and how should they be
set in Apache?

To the best of my knowledge, I'd say that setting an Expires header in
the distant future is all that it really needs. Apache will be
sending the usual cacheability data at the same time (unless you were
doing something to prevent that). Caches make their own decisions
about whether they're going to check or not. Trying to force them to
behave in one way or another, contrary to their inclinations based on
the actual properties of the page, seems to be rarely helpful, and
sometimes counterproductive. So unless you're a world expert in
Cache-control headers, I'd say you'd be safer to leave those out, than
to risk inadvertently saying the wrong thing.

Verify that you're getting the results that you intended, by pointing
Mark Nottingham's "cacheability engine" at some typical pages.

h t h
 
M

Michael Winter

On 08/03/2006 11:51, Jim Higson wrote:

[snip]
Because the resource for a given URL never changes, browser cache is
always safe to use and there is no need to revalidate. What are the
best HTTP header(s) to use to indicate this, and how should they be
set in Apache?

There is no specific method with to mark a resources as indefinitely
'fresh'. However, one can get close by sending an Expires header or a
Cache-Control: max-age directive set far into the future.

The RFC 2616 (HTTP/1.1) has a note on this practice:

To mark a response as "never expires," an origin server sends
an Expires date approximately one year from the time the
response is sent. HTTP/1.1 servers SHOULD NOT send Expires
dates more than one year in the future.

-- 14.21 Expires, RFC 2616


The directives below will prompt Apache to send both an Expires and
Cache-Control header, instructing caches to treat all PNG images
(image/png) as fresh for 365 days from the time of access. That is, each
time a request is made to the origin server, a different expiry date
will be calculated.

ExpiresActive On
ExpiresByType image/png A31536000

These directives require the mod_expires module.

Hope that helps,
Mike
 
J

Jim Higson

Michael said:
On 08/03/2006 11:51, Jim Higson wrote:

[snip]
Because the resource for a given URL never changes, browser cache is
always safe to use and there is no need to revalidate. What are the
best HTTP header(s) to use to indicate this, and how should they be
set in Apache?

There is no specific method with to mark a resources as indefinitely
'fresh'. However, one can get close by sending an Expires header or a
Cache-Control: max-age directive set far into the future.

The RFC 2616 (HTTP/1.1) has a note on this practice:

To mark a response as "never expires," an origin server sends
an Expires date approximately one year from the time the
response is sent. HTTP/1.1 servers SHOULD NOT send Expires
dates more than one year in the future.

-- 14.21 Expires, RFC 2616


The directives below will prompt Apache to send both an Expires and
Cache-Control header, instructing caches to treat all PNG images
(image/png) as fresh for 365 days from the time of access. That is, each
time a request is made to the origin server, a different expiry date
will be calculated.

ExpiresActive On
ExpiresByType image/png A31536000

Out of interest, why not write it as:

ExpiresByType image/png "access plus 1 year"

Which seems to be legal according to this page:
http://httpd.apache.org/docs/2.0/mod/mod_expires.html
These directives require the mod_expires module.

Hope that helps,

It does. I'll ask the server admin to enable the module.
 
M

Michael Winter

Michael Winter wrote:
[snip]
ExpiresActive On
ExpiresByType image/png A31536000

Out of interest, why not write it as:

ExpiresByType image/png "access plus 1 year"

No particular reason. :)

[snip]
Hope that helps,

It does. [...]

By the way, my apologies for the poor grammar in my previous post. I
really shouldn't edit posts just before I post them without a second,
thorough proof-reading.

Mike
 
J

Jim Higson

Michael said:
Michael Winter wrote:
[snip]
ExpiresActive On
ExpiresByType image/png A31536000

Out of interest, why not write it as:

ExpiresByType image/png "access plus 1 year"

No particular reason. :)

Fair enough.
[snip]
Hope that helps,

It does. [...]

By the way, my apologies for the poor grammar in my previous post. I
really shouldn't edit posts just before I post them without a second,
thorough proof-reading.

I later noticed my grammar too was awful in the original post - far too many
commas!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top