Question

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?

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top