2

我正在使用以下设置运行我的生产环境,它似乎正在缩小但没有压缩/压缩响应。

  # Disable Rails's static asset server (Apache or nginx will already do this)
  config.serve_static_assets = false

  # Compress JavaScripts and CSS
  config.assets.compress = true

  # Don't fallback to assets pipeline if a precompiled asset is missed
  config.assets.compile = false

  # Generate digests for assets URLs
  config.assets.digest = true

这是我的js文件,标题不包含gzip或deflate???

$ curl -I http://sctest-perf.herokuapp.com/assets/application-1d21d488644b11e5610fa26bacdbc868.js
HTTP/1.1 200 OK
Age: 0
Cache-Control: public, max-age=31536000
Content-length: 213394
Content-Type: application/javascript
Date: Fri, 08 Jun 2012 20:34:58 GMT
Etag: "1d21d488644b11e5610fa26bacdbc868"
Last-Modified: Wed, 30 May 2012 16:38:32 GMT
Status: 200 OK
X-Content-Digest: 914bc6f80b0619be63c1302821ccc24a082ace53
X-Rack-Cache: miss, store
X-Request-Id: 76cb22ef23b73c440878569eec42ed4d
X-Runtime: 0.001314
X-Ua-Compatible: IE=Edge,chrome=1
Connection: keep-alive
4

2 回答 2

9

您需要编辑config.ru位于项目根目录中的文件:

require ::File.expand_path('../config/environment',  __FILE__)

# Add beautifully gzipped responses
use Rack::Deflater

run YourApp::Application
于 2012-06-08T20:56:37.770 回答
3

您也可以尝试使用其中一种可以帮助进一步优化资产服务流程的 gem。

https://github.com/romanbsd/heroku-deflater

https://github.com/mattolson/heroku_rails_deflate

如果我没记错的话,使用use Rack::Deflater也会压缩图像,这会浪费资源并且没有用处。

于 2013-06-20T15:12:29.593 回答