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?
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:
Application.css includes everything in styles folder. What your precompile path should look like is this:
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.
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:
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:
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.