gpt4 book ai didi

ruby-on-rails - 缺少 gzip 版本的 css 和 js Assets

转载 作者:行者123 更新时间:2023-12-03 09:23:58 26 4
gpt4 key购买 nike

我将 Rails 4.2 用于一个非常简单的项目。当我运行 rake assets:precompile (用于开发和生产环境)我得到一个 application-xyz.jsapplication-xyz.css在公共(public)/ Assets 中归档。但是不会创建 gzip 版本,即没有 application-xyz.js.gz没有application-xyz.css.gz .我不知道禁用此功能的任何选项。我错过了什么吗?

最佳答案

Sprockets 3 不再生成压缩版本的 Assets 。根据this issue这主要是因为它们很少被实际使用。

您可以通过在预编译后自己压缩资源来恢复此功能,例如 example capistrano task由 Xavier Noria 使用 find遍历 Assets 文件夹中的所有 css 和 js 文件,然后使用 xargs将它们传递给 gzip :

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

关于ruby-on-rails - 缺少 gzip 版本的 css 和 js Assets ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29700369/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com