Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Rails-generated JS file that I want to distribute via CloudFront (using my Rails app on EC2 as the origin server). Does anyone know which headers I should use in the response for my JS file to ensure that the end user's browser does not cache the JS file?

I know CloudFront does not respect any expires headers that are less than 1 hour... but the docs say those headers are still passed on to the client:

Am I safe using the following?

Cache-Control: no-cache
Pragma: no-cache
share|improve this question
It seems like those headers make it so that CloudFront doesn't even cache the content... every request seems to be hitting my origin server. – Aaron Gibralter May 29 '11 at 2:39
Why are you using CloudFront for a file that shouldn't be cached? – Smudge Jun 1 '11 at 20:40
up vote 1 down vote accepted

Hmm so it turns out I don't really want to be doing that at all. CloudFront respects no-cache headers so this will, in fact, not cache the JS file on CloudFront for an hour. It doesn't really make sense to use CloudFront for this... more information can be found on my AWS Forums post.

share|improve this answer

Apparently CF no longer respects no-cache header any more. I tried a few combinations of Cache-Control, Pragma, and Expires headers but CF always returns X-Cache:Hit from cloudfront after the first access. It does however pass these headers on to the client as-is.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.