Corin
2010-Jan-20 23:29 UTC
enhancement for write_asset_file_contents of AssetTagHelper module [patch]
Hi all, 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: original: stylesheets/jquery/redmond/images/test.png cached: stylesheets/images/test.png 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. Corin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Marcin Seroczynski
2010-Jan-22 12:21 UTC
Re: enhancement for write_asset_file_contents of AssetTagHelper module [patch]
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 Martin On Jan 21, 12:29 am, Corin <wakath...@gmail.com> wrote:> Hi all, > > 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: > > original: stylesheets/jquery/redmond/images/test.png > cached: stylesheets/images/test.png > > 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. > > Corin > > join_asset_file_contents_for_css.diff > 2KViewDownload-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Chris Cruft
2010-Jan-22 15:18 UTC
Re: enhancement for write_asset_file_contents of AssetTagHelper module [patch]
The thought of parsing the stylesheets to replace url references seems pretty clunky. Could something like Sass address this problem more cleanly? On Jan 20, 6:29 pm, Corin <wakath...@gmail.com> wrote:> Hi all, > > 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: > > original: stylesheets/jquery/redmond/images/test.png > cached: stylesheets/images/test.png > > 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. > > Corin > > join_asset_file_contents_for_css.diff > 2KViewDownload-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Corin
2010-Jan-22 15:57 UTC
Re: Re: enhancement for write_asset_file_contents of AssetTagHelper module [patch]
Hi Marcin, may be I didn''t understand you correctly, but I think config.action_controller.asset_host is not related with the problems I address with the patch. If you set asset_host to "/public" for development, urls look like this (resolved by browser): original: public/stylesheets/jquery/redmond/images/test.png cached: public/stylesheets/images/test.png After my patch: original: public/stylesheets/jquery/redmond/images/test.png cached: public/stylesheets/jquery/redmond/images/test.png If you set asset_host to a different host, like "http://mydata.com:123/data/": original: http://mydata.com:123/data/stylesheets/jquery/redmond/images/test.png cached: http://mydata.com:123/data/stylesheets/images/test.png After my patch: original: http://mydata.com:123/data/stylesheets/jquery/redmond/images/test.png cached: http://mydata.com:123/data/stylesheets/jquery/redmond/images/test.png 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. Corin On 22.01.2010 07:21, Marcin Seroczynski wrote:> 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 > > Martin >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Corin
2010-Jan-22 16:02 UTC
Re: Re: enhancement for write_asset_file_contents of AssetTagHelper module [patch]
Hi Chris, 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. Corin On 22.01.2010 10:18, Chris Cruft wrote:> The thought of parsing the stylesheets to replace url references seems > pretty clunky. Could something like Sass address this problem more > cleanly? >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.