Posted about 1 month ago. Visible to the public.

Disabling client caching with Cache-Control: no-store

Browsers usually cache website content in order to provide the user with faster responses. Examples are returning to a website using the "Back" button, or reopening a browser and restoring previous tabs.

However, there are applications where this kind of client caching produces annoying results: a time tracking tool may show a wrong clock-in state, or an SPA todo app may display an outdated list. In these cases, client caching should be disabled.

In order to prevent client caching, set a Cache-Control header of no-store. This tells the browser to not cache this response, and it will fetch a fresh copy any time the page is opened again.

You can do that by adding a filter to your ApplicationController like this:

before_filter :disable_browser_caching! def disable_browser_caching! response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate' end

Keep in mind that reverse proxies, caches, or a CDN may overwrite these settings.

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Owner of this card:

Dominik Schöler
Last edit:
26 days ago
by Dominik Schöler
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Dominik Schöler to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more