Preventing Heroku from using precompiled assets in development mode

2.4k views Asked by At

Currently it seems Heroku is determined to pre-compile assets when I push my code up to my instances.

This is great for production servers, however for my "RAILS_ENV=development" server, this causes issues, as I now get pages with all the JavaScript files served up individually from my asset manifest, and then another file with the same code all grouped up as the pre-compiled asset.

This cause my jquery datatables libraries to break, throwing popup errors, which I don't get on my local environment (development or production) or in my production Heroku instance.

Is there anyway to disable pre-compilation of assets on Heroku for development mode instances ? Or is there any reason why these aren't already disabled on development Heroku servers already ?

3

There are 3 answers

2
John Beynon On BEST ANSWER

If Heroku detect a public/assets/manifest.yml file then they will not attempt to precompile your assets and assume you are dealing with them yourself. More details at http://devcenter.heroku.com/articles/rails31_heroku_cedar

1
Michael Irwin On

AFAIK, Heroku has to precompile assets to work around their readonly FS and the fact that the Rails asset pipeline wants to write files to the FS. The only thing I could suggest would be to work out why your assets are breaking when being compiled.

0
Urkle On

I worked around this by adding some voodoo to my Rakefile to disable the assets:precompile rake task.

first I add the user-env-compile labs component

heroku labs:enable user-env-compile

then add this to the beginning of my Rakefile

# found from http://blog.jayfields.com/2008/02/rake-task-overwriting.html
# used by conditional heroku asset compile magick
class Rake::Task
  def overwrite(&block)
    @actions.clear
    enhance(&block)
  end
end

Then I add this rake task in lib/tasks/disable_assets_on_heroku.rake

if ENV['RAILS_ENV'] == 'development'
  namespace :assets do
    task(:precompile).overwrite do
      puts "Asset precompile skipped in #{ENV['RAILS_ENV']}"
    end
  end
end