when using stylesheets caching in rails, one might get problems if the stylesheets contain relative urls and the cache file is generated in a different folder than the original one.
Example
original: stylesheets/jquery/redmond/index.css
cached: stylesheets/cached.all.css
If the stylesheet contains relative links like "url(images/test.png)" it get's resolved like this by the browser:
The attached patch contains a join_asset_file_contents_for_css methode, which gets called by write_asset_file_contents in case the asset is a stylesheet.
Instead of a simple join, it parses the css and updates all urls as needed.
It would be great to take advante of:
config.action_controller.asset_host = "http://static%d.domain.com"
We are serving static content from different server/location with
different URL (just as YSlow describes it) and we have to add absolute
URLs in CSS files to serve those files from those domains.
This feature should work same as all other helpers/methods for
generating URLs for static content, e.g. image_tag
So there should be no need at all to set absolute urls in the stylesheets, as the browser does the resolving of the external url's relative to the location of the css.
The main reason for my patch was that external libraries like jquery ui-plugin etc. come with their own finished .css files. Without my patch, caching doesn't work fully transparent as it should. One would also have to adjust these css files manually everytime a new version of the plugin is installed.
Speed shouldn't be affected too, as the parsing is done only once when the cached file is created.