1

The CSS and Javascripts in my Rails 4 app fails to load on production, but was successful in staging. The only difference between between config/environments/staging.rb and config/environments/production.rb is this line:

config.assets.compile = true on staging, and

config.assets.compile = false on production.

In both staging and production, I do rake assets:precompile on during deployment. Yes, the fingerprinted assets are happily situated at public/assets

It is tempting to just raise my hand, cry "What the heck, I still have other things to code", and just set config.assets.compile = true on production, but as I understand this enables Live Compilation, which dynamically compiles Sass and CoffeeScripts, and I do NOT want that kind of performance tax on our live site.

However, setting config.assets.compile = false in production does NOT generate the proper fingerprinted URL to point to the precompiled assets properly.

In staging, my application.css is happily pointed to https://staging.example.com/assets/application-8b1ca5ff4a98a7b28b0e932fe7412421.css. Which is well and good and bliss and wonderful.

In production, it frustratingly points at https://www.example.com/stylesheets/application.css

How do I then I still use Assets Pipeline (Sprockets) without Live Compilation on production? Anybody who could help me before I run out of hair would be truly appreciated.

Community
  • 1
  • 1
Ardee Aram
  • 4,740
  • 8
  • 36
  • 37

1 Answers1

0

I think I know the answer. Will leave my findings here for future visitors.

It's a timing issue in my deployment system (Amazon OpsWorks), where the code is deployed, then assets:precompiled. The first deployment does not work. The second does however. The system does not assets:precompile when the md5sum of all app/assets does not change.

Which leads me to conclude the following

if config.assets.compile = false

Rails looks for public/assets/manifest-md5hash.json. If it exists, it gives the /assets/application-md5hash.css fingerprinted version. If it does not exist, it gives the /stylesheets/application.css version.

Ardee Aram
  • 4,740
  • 8
  • 36
  • 37