Ubuntu -> Apache -> Phusion Passenger -> Rails 2.3

The primary a part of my website responds for your clicks. So, should you click a hyperlink, it'll give back onto the destination, and instantly regenerate your page.

But, should you hit the rear button, you do not begin to see the new page. Regrettably, it isn't turning up with no manual refresh it seems the browser is caching it. I wish to make certain the browser doesn't cache the page.

Individually, I do wish to set far-future expiration dates for those my static assets.

What's the easiest method to solve this? Must I solve this in Rails? Apache? Javascript?

Thanks for your help, Jason

Alas. Neither of those suggestions forced the behaviour I am searching for.

Maybe there is a javascript answer? I possibly could have rails create a timestamp inside a comment, then possess the javascript determine when the occasions are within five seconds (or whatever works). If so, then fine, but when no, then reload the page?

Do you consider this could work?

Thanks for your help,


Finally figured this out - http://blog.serendeputy.com/posts/how-to-prevent-browsers-from-caching-a-page-in-rails/

..in application_controller.rb..

  before_filter :set_cache_buster

  def set_cache_buster

    response.headers["Cache-Control"] = "no-cache, no-store, max-age=, must-revalidate"

    response.headers["Pragma"] = "no-cache"

    response.headers["Expires"] = "Comes to an end, 01 Jan 1990 00:00:00 GMT"


Regrettably, you can't guarantee that the browser won't cache a webpage. It's not possible.

However, you are able to tell browsers that implement caching standards to not cache a webpage. You need to do this with http headers like:

Pragma: no-cache


Cache-Control: no-cache

So in rails, you would employ:

response.headers["Pragma"] = "no-cache"

response.headers["Cache-Control"] = "no-cache"

I suggest you include both, just just in case. Either should work with most browsers.

I have tried personally this line with a few success within the controller. It really works in Safari and Ie however i haven't seen it use Opera.

response.headers["Expires"] = "#"

For the second point, if you are using the the rails assistant techniques like


and then leave the default configurations in your webserver, the assets are usually cached pretty much.

The cleanser way is always to write a Rack middleware, which changes the Cache-Control header according to some logic (for instance, just for application/xml mime-type). Or, to have an uglier, but nonetheless working approach, you could alter the ActionDispatch::Response::DEFAULT_CACHE_CONTROL constant to 'no-cache'. Obviously, when the controller and/or action granularity is needed, then it is better to get this done within the controller.