Rails using cached application.css despite changes
Solution 1
I had the same issue. I stopped the server, executed rm -fr tmp/cache
, and my css files were finally rebuild.
Solution 2
First, the usual cache clearing sanity checks might help. Clear browser cache. Clear server file cache (if you're in dev/test or can afford to in production) and sass-cache :
rake tmp:cache:clear
rm -fr tmp/sass-cache #or 'compass clean' if using compass
If that doesn't help, maybe Rails compiled ANOTHER application.css elsewhere (that didn't get removed by the cache clearing)?
For example, I ran compass watch app/assets/stylesheets/application.css.scss
for debugging purposes and it created a public/assets/application.css file which, by virtue of it's location in public/, prevented any new application.css.scss stylesheet changes from being noticed by Rails. Once I removed it, the application again pulled from the .scss stylesheets. This is just one example of accidental overriding file creation. Try running a find on the entire application directory looking for any generated application.css files, doing this after the cache clearing to avoid those showing up in your results.
(FYI, to avoid my specific issue, I now run compass watch with --css-dir pointed at the cache to prevent my issue
$ compass watch app/assets/stylesheets/application.css.scss --css-dir tmp/cache/
)
Solution 3
I've had a similiar issue after running rake assets:precompile
in development. Maybe Rails is serving precompiled assets from public/assets
? Try cleaning that up.
You shouldn't need to touch aplication.css.scss in development, rails should serve the new content whenever one of the @included files changes.
Also, make sure you have the following in config/environments/development.rb
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
Solution 4
If you replace @import 'file.css';
with @import 'file';
in your application.scss
that should allow it to be auto-refreshed in development mode
I had been using bin/rails tmp:clear
until I removed the file extension
Solution 5
To wipe out the asset pipeline cache, a brute force rm -rf tmp/* will suffice. This has certainly fixed a few otherwise inexplicable CSS and JavaScript glitches in my experience. As a preventative measure, it might also be a good idea to clear the cache after upgrading gems or changing the asset pipeline configuration, although this may just be superstition.
Finally, if you are experimenting with rake assets:precompile in your development environment (more on this in a later article), you’ll also want to rm -rf public/assets/* afterwards to clean that up.
http://blog.55minutes.com/2012/02/untangling-the-rails-asset-pipeline-part-1-caches-and-compass/
Rui Jiang
Updated on June 10, 2022Comments
-
Rui Jiang almost 2 years
I have a Rails 3.1 application that uses SASS. The
application.css.scss
file looks like:@import 'reset.css'; @import '960.css'; @import 'pages/master.css.scss';
I have a watchr script that touches
application.css.scss
whenever one of the @imported files is changed.For a while this setup worked fine. Ever since last week (and I'm not sure why), Rails has been pulling a cached version of
application.css
for the webpages despite all my attempts at restarting the app, re-touchingapplication.css.scss
, etc. I've also deleted.sass-cache
to no effect.Any ideas?
-
thatmiddleway about 11 yearsugh, that was such a pain to debug. And it just cropped up out of nowhere. Thanks for the tip, total lifesaver.
-
Chloe over 4 yearsWon't work if you have variables or Sass in your
application.scss
! -
Chloe over 4 yearsOMG this is the answer I've been looking for for 6 hours! It must be some type of miracle that you answered 14 days before me on a 9 year old question! (Rails 5.0)
-
pixatlazaki almost 4 yearsAnyone know why this is?
-
coryetzkorn almost 3 yearsThis finally fixed it for me! CSS changes are now automatically picked up on page refresh after removing the file extensions from imports.
-
Andrii over 2 yearsworks for me also with scss instead of css! thanks!