Ruby   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ruby-on-rails – 缺少gzip版本的css和js资产大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_944_0@
我正在使用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

大佬总结

以上是大佬教程为你收集整理的ruby-on-rails – 缺少gzip版本的css和js资产全部内容,希望文章能够帮你解决ruby-on-rails – 缺少gzip版本的css和js资产所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。