views:

29

answers:

2
[i]ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/png A2592000
BrowserMatch "MSIE" brokenvary=1
BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
BrowserMatch "Opera" !brokenvary
SetEnvIf brokenvary 1 force-no-vary[/i]

saw this code in a sample .htaccess recently.

Presumably ExpiresByType sets an expiry time on images - is that related to the visitors browser cache? and what does A2592000 translate to?

and what does the "brokenvary=1" imply? I gather it's looking for a UserAgent, but then what?

thanks!

+1  A: 

ExpiresByType is an Apache Directive of the mod_expires module that generates 'Expires' and 'Cache-control' http response headers. These headers tell a browser that it is allowed to cache the resource for a specific amount of time.

From the documententation ( http://httpd.apache.org/docs/2.0/mod/mod_expires.html ) :

'A' means the client's access time should be used.

An example from the same page might explain things:

# enable expirations
ExpiresActive On
# expire GIF images after a month in the client's cache
ExpiresByType image/gif A2592000
# HTML documents are good for a week from the
# time they were changed
ExpiresByType text/html M604800
ivy
thank you also!
Ross
+1  A: 

Presumably ExpiresByType sets an expiry time on images - is that related to the visitors browser cache?

Yes. mod_expires allows an easy setup of expiration rules based on the type.

But the expiration time specifies only the freshness time of a certain response. This does not necessarily mean that the response is cacheable. But in general, any successful response is cacheable unless there are restrictions:

Unless specifically constrained by a cache-control (section 14.9) directive, a caching system MAY always store a successful response (see section 13.8) as a cache entry, MAY return it without validation if it is fresh, and MAY return it after successful validation.

So unless you specify the response not to be stored at all (i.e. using no-store), the response may be stored by both public caches (shared caches) and private caches (local caches).


And what does A2592000 translate to?

The freshness time of a response can be expressed using either an absolute time value (e.g “2010-10-09”) or a relative time value (e.g. “tomorrow”). The date format A2592000 uses a latter time value as A denotes access time and 2592000 is the number of seconds that are added. So A2592000 means “2592000 seconds from the time of access on”.


And what does the "brokenvary=1" imply? I gather it's looking for a UserAgent, but then what?

Apache has some special purpose environment variables where force-no-vary is one of them:

This causes any Vary fields to be removed from the response header before it is sent back to the client. Some clients don't interpret this field correctly; setting this variable can work around this problem. Setting this variable also implies force-response-1.0.

Now the Vary header field is used to specify a list of header field names the server used to select the response among multiple representations:

A server SHOULD use the Vary header field to inform a cache of what request-header fields were used to select among multiple representations of a cacheable response subject to server-driven negotiation.

So if you’re using content negotiation and a requested generic URL like /document.html is requested and there are multiple representations of that resource (e.g. in English and German) and your server selects the German variant as Accept-Language states the value de, the server would include a Vary field containing Accept-Language to let the caches know that the selection was based on the value of Accept-Language.

But some user agents don’t get this right. And in that cases the Vary header field should not be sent that can be done by setting the special purpose environment variable force-no-vary.

Gumbo
thanks for the very detailed response + links
Ross