Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku is serving old assets for Rails 5 application

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.

like image 856
YigitOzkavci Avatar asked Sep 21 '16 13:09

YigitOzkavci


People also ask

How do I Precompile assets in Heroku?

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.

What does rake assets Clean do?

rake assets:clean removes compiled assets. It is run by cap deploy:assets:clean to remove compiled assets, generally from a remote server.

What is asset pipeline Rails?

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.


1 Answers

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

like image 130
Sandeep Kapil Avatar answered Sep 30 '22 19:09

Sandeep Kapil