Disable page caching in all browser

Many times we face some serious issue while dealing with web page visibility after and before login and that happens due to browser’s property to cache pages.

Here is the solution to avoid browser caching problem using HTML and rails 3 :-

In application_controller.rb add

  before_filter :set_cache_buster

  def set_cache_buster
   response.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
   response.headers['Pragma'] = 'no-cache'
   response.headers['Expires'] = 'Fri, 01 Jan 1990 00:00:00 GMT'

But above solutions does not work for all browsers. Like you will still face issue in browser like safari and in some versions of IE too. So to avoid it all, in layouts/application.html.erb

  <body onunload="">

Now, it will work like a charm…cheers 🙂


One thought on “Disable page caching in all browser

  1. Sambit Mohanty. says:

    This preventing caching for FF and Chrome, but not in IE 11. Is there anything more to do for IE??

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s