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

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...