3

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 ?

Phantomwhale
  • 1,789
  • 1
  • 16
  • 30

3 Answers3

2

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

John Beynon
  • 37,398
  • 8
  • 88
  • 97
  • 1
    This would involve having to have a separate set of code I push to development and production, I guess (as otherwise production would stop pre-compiling assets too !) Thanks for the tip - can get me up and running, but I wonder if herkou might offer a solution where I don't need to have different set of code / git branch for development heroku (e.g. ENV variable, or use a Ruby environment rb script value) – Phantomwhale Jan 23 '12 at 05:49
  • If a public/assets/manifest.yml is detected in your app, Heroku will assume you are handling asset compilation yourself and will not attempt to compile your assets. In Rails 4 the there should be a public/assets/manifest-.json instead. On both versions you can generate this file by running $ rake assets:precompile locally and checking the resultant files into Git. – Michael Minter Apr 10 '14 at 16:44
0

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
Urkle
  • 1,520
  • 13
  • 12
0

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.

Michael Irwin
  • 3,119
  • 5
  • 24
  • 40
  • I belive it is because they are being loaded twice. Once as the development mode rails deconstructs the JS manifest file and includes all the individual JS links in the page, and then again as the page goes on to load the pre-compiled JS manifest which contains all the code again. This does not happen on my local development machine (which correctly has no pre-compiled assets) or any production environment (where all assets must be pre-compiled) – Phantomwhale Jan 23 '12 at 03:43