Show flash messages on cached pages

— August 8, 2007 at 15:38 PDT

If you've ever used Rails page caching, you've probably run into the situation where you wanted to cache a page that had essentially static content, but couldn't because it showed a flash message. I ran into this recently, and thought it would be really slick to move the flash rendering from the server to the browser, so that the page content could be cached but the flash could still be rendered from a cookie. I mentioned my idea to a friend over at Pivotal Labs and he said "Oh, we did the same thing just last week." What they did was very close to what I wanted, and they were ready to release it to the wild, so I sat down with pivot Brian Takita and spent a little while working with him to extract the feature, document it and package it as a Rails plugin.

The result: the Cacheable Flash plugin. Brian's post has a good description, but also checkout the README. For the moment this affects the flash for all actions in a controller, but Brian and I are looking into :except/:only options to allow finer-grained control if that is ever needed.

To install:

ruby script/plugin install svn://

Thanks to Brian and Pivotal for this slick contribution. (By the way, doing TDD in JavaScript with JS-Unit is pretty freaking cool.)

6 commentscache, flash, pivotal, plugin, plugins, rails

  1. Matt Aimonetti2007-08-08 16:50:31

    very useful, thanks for sharing.

  2. Tyna2007-09-10 19:40:54

    Man you don't even know how long I've waited for this since disabling my own Movable Type widget (that doesn't work since Haloscan bypasses that code).


  3. Arnold2007-09-14 15:36:04

    Thanks for explanation for us, for me that was really kind of PROBLEM :)

  4. weepy2007-09-27 13:39:37

    Actually I've just written a plugin (called CacheBack) that has similar functionality, but is more generic - so you can cache not just the flash, but other aspects e.g. login details in the nav or show non-sensitive conexts to each logged in user.

    If anyones interested - i can make it public.

  5. Fjan2007-10-01 19:36:34

    @weepy: Our site does something similar with the 'logged in as ...' info on the top right of cached pages. It works fine now, but it turns out to be a tad harder than you might expect if your site is reachable under more than one url. Changing the top level domain is something that is typically used to show localised versions (.uk, .de, etc.) and modern browsers do not allow you to read the cookie from another tld. Our solution is to have a special controller do a few redirects to sync up the necessary cookies across the domains (our site is For the flash plugin mentioned here this is not a problem.

  6. weepy2007-10-02 08:15:40


    Why would your users change the tld and expect to keep their session ?

    BTW - I have a public version of Cacheback - if your interested I can email it to you.

Sorry, comments for this article are closed.