RJS templates and Caching

Hi All,

I'm using RJS templates extensively in my app, but now that I've gone
back and started trying to cache some common things, I'm finding that
RJS templates and caching don't seem to go well together.

It seems that I can't do any page or action caching on an rjs template,
because even though it gets cached, when it's served back up the mime
type is text/html instead of text/js, and the browser tries to plop the
javascript into the page rather than executing it.

I can cache content in the partials that the rjs template references
via fragment caching, but that's very limited because, as I understand
it, fragments can't be cached based on url paramaters like the other
caching methods.

Does anyone have any good ideas on how to cache rjs templates?

Thanks!
Tom

I think I figured it out. You can use action caching with rjs
templates, you just need to add an after_filter on that action that
looks like this (name it whatever you want):

def returns_rjs
    @headers["Content-Type"] = 'text/javascript'
end

Then your rjs actions can be cached like their rhtml counterparts.

- Tom Lianza