Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails 3.1 asset pipeline css caching in development

I'm a bit confused as it seems like the application.css is including itself twice, once when it lists the resources from the manifest and then a cache of that. So when I delete an individual file it still seems to stay alive inside the application.css file.

application.css (source)

/* *= require twitter/bootstrap *= require_self *= require_tree ./common *= require_tree ./helpers */ 

Which works as expected and outputs in dev mode all the relevant individual files

development.rb

  # Do not compress assets   config.assets.compress = false    # Expands the lines which load the assets   config.assets.debug = true 

output

<link href="/assets/twitter/bootstrap.css?body=1" media="screen" rel="stylesheet" type="text/css" /> <link href="/assets/application.css?body=1" media="screen" rel="stylesheet" type="text/css" /> <link href="/assets/common/announcement.css?body=1" media="screen" rel="stylesheet" type="text/css" /> <link href="/assets/common/button.css?body=1" media="screen" rel="stylesheet" type="text/css" /> <Blah blah> 

application.css (output)

This should be blank? Since all I have in my application.css file is the manifest and no actual css but instead i get all my concatenated code 106kb long.

IE if I remove a file in the common directory, it doesn't go away. It is no longer listed in the output but the css still appears from the application.css

like image 733
holden Avatar asked Nov 16 '11 21:11

holden


People also ask

How do you Precompile rails assets?

To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.

How asset pipeline works in Rails?

The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB. Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets.


2 Answers

I had a problem like this before. It was caused after I had precompiled the assets it was going after the applcation.css inside the public folder as well as in the apps directory. I'm not sure how to fix it so that it doesn't keep happening while in dev mode but if you delete your /public/assets directory it should fix it.

Check and see if you have a public/assets folder, if you do and it's full, it's probably why you're seeing double.

like image 144
ere Avatar answered Sep 24 '22 23:09

ere


There is currently (2012-09-24) a bug in rails/sprockets causing it to not properly detect imported files.

This should be fixed in rails 3.2.9 and later but in the mean time, you can work around it as follows:

  1. Kill the rails instance
  2. rm -rf tmp/cache
  3. Start the rails instance

You should now be seeing the correct css.

like image 25
Peter Hoeg Avatar answered Sep 23 '22 23:09

Peter Hoeg