I'm having a hard time deciding whether to use Apaches' built-in ETags or the Expires/Cache-Control combination for my static files (.js, .png, etc.).

I'm running a single-server setup, nothing fancy.

I mostly understand how it all works and I have had both setups running, tweaking different things along the way.

They seem very similar. About the only differences I can find is Apaches' ETags do not allow you to define the amount of time before the components' expiration. Also, when using ETags I see a new request for each component resulting in a 304 if the file is not modified.

For those reasons, I am leaning towards the Expires/Cache-Control combo, but what is your opinion of which to use?

  • Two good answers below (@Michael Graff and @0x44).
    – Jeff
    Dec 14 '09 at 14:11

It depends on how often your files change. It they get changed frequently, the Expires/Cache-Control combo may introduce latency for your clients to get the new contents. On the other hand, ETag ensures a cache revalidation on each request, which would make sure that your clients get the newest contents all the time.

If there's any chance for you to go with a multi-server setup, I'd suggest you to tune the FileETag directive (remove the INode option, at least) though, as it may produce different ETags on different servers.


It depends on how you refer to your static content as well. I put 10 year expiration settings on most of my static files, but in all cases those are referred to from dynamic content using a query-string format of ?timestamp. Since this is more or less identical to using an ETag that includes the file's timestamp as part of the tag, I would recommend for purely static configurations to go with ETags.

Also note that you can choose ETags now, and later switch. It's harmless. You can also do all of the different methods together. I believe Ruby on Rails does the if-modified-since dance, etags, and cache-control, and can mix and match. For specific static configurations, I can't imagine you need to do them all, but there's little harm in doing more than one.

I will say it is very hard to get a far-future Expires header out of caches, but the rest is fairly easy. It just depends on how much traffic you're willing to live with, as the hardest to remove from remote caches is the best in terms of traffic efficiency.

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.