I've deployed a new version of a Rails 5 app on Heroku, running on cedar-14 stack. It didn't precompile while deploying, so I did heroku run rake assets:precompile
manually. Still, I can see it includes old assets while requiring css
and js
files.
My files are in app/assets
so it's not possible that directory isn't in assets compile path.
My config on application.rb
and production.rb
:
config.assets.compile = true
# I checked the environment variable, it responds to 'enabled',
# which would return true for the option.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Which I changed to expire old assets.
config.assets.version='1.1'
I tried these, but they didn't work:
$ heroku restart
$ heroku run rake assets:precompile
$ heroku run rake assets:clobber
The weird thing with these is that they do not affect assets in heroku server, which I checked with $ heroku run ls public/assets
. Even after $ rake assets:precompile
, even though it says this:
WRITING /app/public/assets/application-{VERY_LONG_HASH}.js
WRITING /app/public/assets/application-{VERY_LONG_HASH}.js.gz
WRITING /app/public/assets/application-{VERY_LONG_HASH}.css
WRITING /app/public/assets/application-{VERY_LONG_HASH}.css.gz
when I peek with the $ heroku run ls public/assets
, I still see old assets staying there.
EDIT: I solved it by deleting all the local assets in public/assets
, recompiling them with $ rake assets:clean && rake assets:precompile
and including these assets in my git
repository. Here is one concern:
Shouldn't heroku be responsible of compiling my assets on the fly? I think I shouldn't be compiling my assets everytime I deploy my application. Thanks.
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.
rake assets:clean removes compiled assets. It is run by cap deploy:assets:clean to remove compiled assets, generally from a remote server.
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.
Run on local
RAILS_ENV=production bundle exec rake assets:precompile
Next git add .
Next got commit -m"assets precompile"
Next git push origin yourBranchName
Deploy on heroku and you are done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With