ruby-on-rails – 缺少gzip版本的css和js资产

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 缺少gzip版本的css和js资产前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用Rails 4.2进行一个非常简单的项目.当我运行rake资产:预编译(用于开发和生产环境)时,我在public / assets中获得了application-xyz.js和application-xyz.css文件.但是不会创建gzip版本,即没有application-xyz.js.gz,也没有application-xyz.css.gz.我不知道有任何禁用此功能的选项.我错过了什么吗?

解决方法

链轮3不再生成gzip压缩版本的资产.根据 this issue,很大程度上是因为它们很少被实际使用.

您可以在预编译后通过gzipping资源自行恢复此功能,例如Xavier Noria使用find来使用find迭代资源文件夹中的所有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
原文链接:https://www.f2er.com/ruby/274395.html

猜你在找的Ruby相关文章