Put / assets in .slugignore for Heroku deployments using asset_sync (S3 / CDN)

I'm not sure there is an existing way to do this, but with the asset_sync function, the idea is that the assets are served from S3 or some CDN (like a cloud), so you don’t need to be part of the application. Is it possible to have / assets in .slugignore on Heroku and still get the asset: precompile and asset_sync work? If I just put / assets in .slugignore, they are not compiled with a digest, and links to assets without a fingerprint and therefore do not work.

+4
source share
2 answers

Editing .slugignore does not work there, because file exclusion begins before all stages of compilation on Heroku. But we need to compile them all, move them to S3, and only then delete them.

I wrote the code in my Rakefile, a small script that deletes all unusable files using the extension filter:

Rake::Task["assets:precompile"].enhance do puts 'my assets:precompile hook is started!' dir_path = "#{Dir.pwd}/public/sites-fromfuture-net/" records = Dir.glob("#{dir_path}**/*") records.each do |f| if f =~ /.*.png$/ or f =~ /.*.jpg$/ or f =~ /.*.eot$/ or f =~ /.*.svg$/ or f =~ /.*.woff$/ or f =~ /.*.ttf$/ or f =~ /.*.otf$/ or f =~ /.*.css$/ or f =~ /.*.js$/ or f =~ /.*.wav$/ then File.delete(f) end end # puts Dir.glob("#{dir_path}**/*") puts 'my assets:precompile hook is finished!' end 

And one more thing: I use the hero of the deflater hero, who gzips all css and js assets, so I delete all the .css and .js script files, but I do not delete .css.gz and .js.gz, due to check rail resources.

+1
source

Have you read this article? - https://devcenter.heroku.com/articles/cdn-asset-host-rails31

The Asset Sync section seems to indicate that the assets can be precompiled to the hero, and then the asset_sync gem will unload them from there into your s3 bucket (as part of the precompilation stage), the article does not mention the use of .slugignore

0
source

Source: https://habr.com/ru/post/1443126/


All Articles