0

I have a strange issue where only some of our assets are being pre-compiled on production. Our application.css file is compiled and updated, but our mobile.css file hasn't been compiled since July, and the site still points to this older version.

Stranger still, we don't get this problem on our staging or local environments. All assets are precompiled and the latest versions are served on the site.

In July we upgraded the site to rails 4 and changed our configuration to this:

# Rails 4 changed the precompile to only for app/assets. This will include vendor/assets
config.assets.precompile << Proc.new{|filename, path| %w(.png .gif .css .js .htc .svg .eot .woff .ttf).include?(File.extname(filename)) && path =~ /(\/lib\/assets)|(\/vendor\/assets)/ }


config.assets.precompile += [
  'form.css',
  'homepage.css',

  …

  #mobile
  'common_mobile.css'
]

Any ideas on what could cause this?

elstgav
  • 1,001
  • 7
  • 20

1 Answers1

1

So typically what you need is the application.js & application.css files to reference all the css & js files to compile them. Anything you don't have in there, you need to have in another manifest file that you add to the precompile path. Or that you add manually to the precompile path.

So if you have:

assets/
  stylesheets/
    application.css
    styles/
    mobile.css

Application.css includes everything in styles folder. What your precompile path should look like is this:

config.assets.precompile += %w(mobile.css)

Now you showed scanning for various extensions. You can really add those to the array, you don't need to grab full file paths or anything fancy.

config.assets.precompile += %w(mobile.css .css .eot .htc)

And so on.

Now keep in mind that if you use folders other than: assets/images, assets/stylesheets or assets/javascripts, add the folders as you need to in the production.rb:

 config.assets.paths << Rails.root.join("app", "assets", "fonts")
 config.assets.paths << Rails.root.join("vendor", "assets", "audio")

Then the wildcards in the precompile path will come into play.

To test this, simply setup production on your computer, and run the rake command:

RAILS_ENV=production bundle exec rake assets:precompile

And look at the output in public. I'm pretty sure the environment defaults to production for that command, but may as well be explicit.

agmcleod
  • 13,321
  • 13
  • 57
  • 96
  • thanks, but it looks like the problem is caused by sprockets failing to recognize I need the asset re-compiled. Those assets depend on a stylesheet from a gem. The gem was updated, but it didn't trigger a recompile because the files themselves didn't *technically* change. I'm going to open a new question to investigate. – elstgav Aug 07 '14 at 23:55
  • Ahh. It may be worth while having a `rake assets:clean` in your deploy script. I think ours at work typically run that, but I'm not certain. – agmcleod Aug 08 '14 at 02:47