Last active
July 2, 2019 18:14
-
-
Save fxn/427dca61ec44adf8253b to your computer and use it in GitHub Desktop.
gzip assets with Capistrano
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Compresses all .js and .css files under the assets path. | |
namespace :deploy do | |
# It is important that we execute this after :normalize_assets because | |
# ngx_http_gzip_static_module recommends that compressed and uncompressed | |
# variants have the same mtime. Note that gzip(1) sets the mtime of the | |
# compressed file after the original one automatically. | |
after :normalize_assets, :gzip_assets do | |
on release_roles(fetch(:assets_roles)) do | |
assets_path = release_path.join('public', fetch(:assets_prefix)) | |
within assets_path do | |
execute :find, ". \\( -name '*.js' -o -name '*.css' \\) -exec test ! -e {}.gz \\; -print0 | xargs -r -P8 -0 gzip --keep --best --quiet" | |
end | |
end | |
end | |
end |
The best compression can probably be gained with zopfli, but it is very slow.
Why only .ico ? Can this apply to all kind of images?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for the best compression you must install 7z on your server
7z has optimized version of GZIP