How can I get the Rails asset pipeline to Gzip compress images? It compresses css and js files but not images.
EDIT
Rewritten question. Initially this was about subfolders but it seems Rails isn't compressing any images.
To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.
The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB. Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets.
rails assets:precompile is the task that does the compilation (concatenation, minification, and preprocessing). When the task is run, Rails first looks at the files in the config.assets.precompile array. By default, this array includes application.js and application.css .
From section 4.1.2 in the canonical Rails Guides:
When files are precompiled, Sprockets also creates a gzipped (.gz) version of your assets.
To precompile your assets, use the bundled rake task:
# from command line
RAILS_ENV=production bundle exec rake assets:precompile
UPDATE:
After some research into the subject, I've allegorically found that, while Sprockets compresses JS and CSS assets, it does not compress images. Then I came across this gem: sprockets-image_compressor
I haven't implemented it myself, but it claims to provide lossless compression of image assets using pngcrush and jpegoptim. Interestingly, the docs state the following:
If the environment doesn't have pngcrush and/or jpegoptim installed, the gem will fall back on binaries packaged with the gem.
Again, I haven't used this myself, but if it does what it claims, it might be exactly what you're looking for.
It doesn't compress any images because images are already compressed (like jpeg). So it is not needed for traffic saving purposes.
Which means you cannot do it with any of existing settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With