Heroku is serving old assets for Rails 5 application
Asked Answered
L

2

6

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.

Ligniform answered 21/9, 2016 at 13:11 Comment(1)
Though you solved it, I think the problem was you were doing all operations like assets:clobber and assets:precompile inside a heroku instance of app instead of doing that in your local instance and pushing to heroku. And about your question, I wonder that too since I have started using heroku (i.e 1 year).Granulation
S
2

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

Sunup answered 14/12, 2016 at 6:30 Comment(1)
This is a botched solution.... You don't want to add the compiled assets to your git repository.Aloke
H
0

You need to commit your changes first. Then execute git push heroku yourbranch:master

Hyperkinesia answered 21/9, 2016 at 13:13 Comment(3)
I already have github integration with enabled auto deploy. As I stated, I am pretty sure the application has been deployed.Ligniform
check the status of our code by git status, if it displays any files, then u need to add & commit themHyperkinesia
What I want to know is, do we need to include our precompiled assets for committing? Isn't that violeting the reason behind compiling assets? And as I said, I am sure that the problem isn't with the commits or pushes.Ligniform

© 2022 - 2024 — McMap. All rights reserved.