15

I updated two images and now Heroku is serving one correctly but the other is still the old image. The output of the deploy logs show both images being precompiled with new hashes but the hash used to retrieve one of them (from the application.css file) is still the old hash and it's grabbing the old image somehow.

I'd like to force Heroku to recompile every asset and restart the server (essentially a fresh deploy). Currently it seems to "intelligently" only precompile the assets that it judges as being new. I tried doing rake assets:clobber and rake assets:precompile but it changed nothing -- still using the old hash to grab the old image version for one, but successfully getting the other. Any other options to try?

Erik Trautman
  • 5,883
  • 2
  • 27
  • 35

4 Answers4

21

Expiring the assets manually worked -- changed config.assets.version = 1.0 to 1.1 in config/production.rb. Still not sure what happened, though.

Erik Trautman
  • 5,883
  • 2
  • 27
  • 35
  • This has also fixed my problem with Capistrano, that was not recompiling assets even if some JS had changed – collimarco Dec 18 '16 at 18:30
8

You can now recompile assets without commiting anything.

heroku plugins:install heroku-repo

and then

$ heroku repo:reset --app=appname
$ git push heroku

Source: https://stackoverflow.com/a/9736959/3034747

This command used to accomplish the same thing, but it has been removed and no longer works:

$ heroku repo:rebuild -a appname
mooreds
  • 4,932
  • 2
  • 32
  • 40
Yana Agun Siswanto
  • 1,932
  • 18
  • 30
  • 1
    The removed this command https://github.com/heroku/heroku-repo/commit/fb1306de5813dffadc046e82cd327175ca58c44b – qix Jul 12 '15 at 05:44
  • I also had to use `heroku repo:purge-cache --app=appname` before pushing to heroku for assets to recompile. – ybart Apr 29 '16 at 09:32
  • 1
    @ybart that's `heroku repo:purge_cache --app=appname` – Michael Jul 27 '16 at 16:25
  • 2
    Also, you can install the repo plugin like this: `heroku plugins:install heroku-repo` – Michael Jul 27 '16 at 16:26
0

Gross, but make a small change and redeploy.

You have to actually redeploy because that's when asset compilation happens and your slug is compiled. Just restarting the server with heroku restart, changing config variables, or pretty much anything else won't build a new slug for you.

I just ran into this problem, and this was at least what solved it for me; YMMV.

Steve Ellis
  • 494
  • 5
  • 13
  • The question states that he can see the precompile happen on the assets as he deploys. He wants to force heroku to start from scratch, which a simply change and deploy will not do. – Michael Jul 27 '16 at 16:22
  • Actually, the question says 'it seems to "intelligently" only precompile the assets that it judges as being new.' A deploy does start from scratch, but does not recompile assets if they appear unchanged(doesn't check env variables in this step). Still, @bekicot's answer looks cleaner. – Steve Ellis Jul 27 '16 at 16:46
-1

Stuff like that can happen - why don't you try using heroku run rake assets:clean and heroku run rake assets:precompile to get the assets cleaned on the server

Richard Peck
  • 76,116
  • 9
  • 93
  • 147
  • Unfortunately this doesn't appear to change anything. I'm having the same problem now with another app... – Erik Trautman May 28 '14 at 21:47
  • 3
    This will not work because all you will achieve is recompiling the assets in a fresh worker dyno. Every time a dyno is launched it uses the state from the last compilation, so any changes you make will just be thrown away when it exits. – Eden Townsend Jul 03 '14 at 09:15