2

I use asset_sync to precompile assets and upload them to s3.

During the app lifecycle, assets come and go, and start piling up. At the moment, my slug size is 73mb, partly, I guess, due to the fact that I had some high resolution images in there, which were removed once I didn't need them anymore.

When adding /app/assets/images to .slugignore, the image asset will no precompile, effectvily ignoring the images in there. So while, the slug size was reduced in about 15mb, it's not very effective in reality.

Is there a better way to make heroku ignore the assets I uploaded to s3?

Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244
  • Can't you include them in your `.gitignore`? This will prevent you from sending the file to Heroku to begin with, allowing you to perform a `rake assets:precompile RAILS_ENV=production` locally, thus avoiding the submittal of the files to Heroku at all? – Richard Peck May 04 '14 at 12:37
  • But I use asset_sync which uploading and syncs all assets to s3 (and from there to cloudfront) – Nick Ginanto May 04 '14 at 12:51
  • Yep we use it too - it will sync from your local system to s3 if you use RAILS_ENV=production – Richard Peck May 04 '14 at 13:01
  • but then I need to do it manually every time – Nick Ginanto May 04 '14 at 13:16

1 Answers1

0

The best solution I found for this is to extend the precompile task to delete from the slug all of the static assets, since they were uploaded via asset_sync and are unneeded anymore

original answer at: put /assets in .slugignore for Heroku deployments with asset_sync (S3/CDN)

this reduced the slug size down to about 40mb (from around 90)

this is my rake extend

Rake::Task["assets:precompile"].enhance do
  return "can't run in dev" if Rails.env.development?
  puts 'my assets:precompile hook is started!'
  ["#{Dir.pwd}/public/", "#{Dir.pwd}/app/assets/"].each do |dir_path|
    records = Dir.glob("#{dir_path}**/*")
    records.each do |f|
      if f =~ /.*.png$/ or
        f =~ /.*.jpg$/ or
        f =~ /.*.gif$/ or
        f =~ /.*.gz$/ or
        f =~ /.*.ico$/ or
        f =~ /.*.eot$/ or
        f =~ /.*.svg$/ or
        f =~ /.*.woff$/ or
        f =~ /.*.ttf$/ or
        f =~ /.*.otf$/ or
        f =~ /.*.css$/ or
        f =~ /.*.js$/ or
        f =~ /.*.sass$/ or
        f =~ /.*.css$/ or
        f =~ /.*.scss$/ or
        f =~ /.*.coffee$/ or
        f =~ /.*.wav$/ then
        File.delete(f) if File.file?(f)
        puts "removing #{f}"
      end
    end
    puts Dir.glob("#{dir_path}**/*")
  end
  puts 'my assets:precompile hook is finished!'
end
Community
  • 1
  • 1
Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244