9

According to Heroku documentation:

Heroku now caches 50mb worth of tmp/cache/assets which is a cache directory for the asset pipeline to store intermediate files. This means that future asset compilations will be faster due to not having to recalculate these files.

My question is how do I manually reset or delete this cache so that all of my assets have to be precompiled again? I tried heroku run console and Rails.cache.clear but it did not work. The reason I want to reset the cache is I have changed the config.action_controller.asset_host in my production.rb file but Heroku is not picking up on the change because of the cache.

diasks2
  • 2,033
  • 2
  • 36
  • 61

5 Answers5

16

To purge Heroku's asset cache, you need the Heroku Repo plugin to the Heroku toolbelt. Install that, then use the command

heroku repo:purge_cache

Deploy after purging the cache.

dodgio
  • 2,169
  • 21
  • 19
  • 1
    This takes a minute or two to try out and probably does everything the other answers do and more. Fixed everything for me after trying other solutions forever, thank you – Tom Prats Oct 16 '15 at 06:12
  • 'heroku run rake assets:clobber ...' did NOT work for me. This did. The "takes a minute or two" is key. – traday Jan 21 '16 at 23:18
  • I was getting 'remote: LoadError: cannot load such file -- coffee_script' errors during a heroku push/precompile because some coffee file was cached somewhere on heroku. This is the only cache purge that worked to clear that up. (ie assets:clobber didnt fix it) – Michael May 12 '17 at 15:02
13

Hopefully this helps. To get changes to Heroku in development I run rake assets:clean and then rake assets:precompile RAILS_ENV=production --trace before committing and pushing to Heroku

Kick Buttowski
  • 6,709
  • 13
  • 37
  • 58
user1854802
  • 388
  • 3
  • 14
  • 5
    This worked thanks. Instead of running `rake assets:clean` I ran `rake assets:clobber` as I read that `rake assets:clean` has been replaced with `rake assets:clobber` for Rail 4 http://stackoverflow.com/a/15355381/1276696 – diasks2 Apr 09 '14 at 23:50
  • 1
    ...the key being "before committing and pushing to Heroku". Don't run "rake assets:precompile on Heroku, it won't do anything. – Kees Briggs Mar 06 '17 at 03:21
4

For cleaning assets, run:

rake assets:clobber

Absurdim
  • 233
  • 3
  • 15
  • Thanks. I tried that but it didn't work. It took 6 seconds to precompile on a push before I did the clobber and still 6 seconds after and my files still hadn't changed. – diasks2 Apr 09 '14 at 23:37
1

I had this problem, then i realized I forgot to configure to serve static assets on the production env, inside config/enviroments/production.rb

config. serve_static_files = true
jstnno
  • 1,035
  • 1
  • 11
  • 13
1

As this Stack Overflow answer explains, config.assets.version exists for this purpose.

Most likely, you'll find it in config/application.rb or config/initializers/assets.rb. Change it to any value you want to break the cache next time you deploy to any environment.

Isaac Betesh
  • 2,935
  • 28
  • 37