How are other people handling dynamically loaded less or sass files with rails 3.1?

Hi,

I'm converting an app to use the asset pipeline, and we have a lot of views that are including stylesheets on an as-needed basis. We're injecting the stylesheet_link_tag calls into the layout via content_for/yield.

We're also transitioning to the less css framework, and I want to take advantage of all the fun stuff like variable and mixins, etc. If we continue doing things the way we're doing them now, then each as- needed stylesheet will have to import the file containing all of the variables and mixins.

Is there another approach that people are using to address this? Since css files are precompiled in production mode, I don't think I can put this logic into the css files (I was thinking that by making them erb files I could include additional files in the main css file using the controller and action names).

Thanks, Kristina

I used to do that, but have concluded it wasn't worth it, at least in my case. Since the browser will cache the css, then it is probably actually better to deliver the exact same one for each page so that the browser only downloads it once. Otherwise the css for each page needs to be downloaded and cached separately.

Particularly with css, which don't tend to be huge files anyway, but even with javascript I didn't see that big a difference. And with the javascript, I was always ending up adding the files back on the page as I needed them.