我正在使用以下设置运行我的生产环境,看起来它正在缩小,但不是gzipping /压缩响应。
# 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
答案 0 :(得分:9)
您需要编辑位于项目根目录中的config.ru
文件:
require ::File.expand_path('../config/environment', __FILE__)
# Add beautifully gzipped responses
use Rack::Deflater
run YourApp::Application
答案 1 :(得分:3)
您还可以尝试使用这些宝石中的一种,以帮助进一步优化资产流程的服务。
https://github.com/romanbsd/heroku-deflater
https://github.com/mattolson/heroku_rails_deflate
如果我没弄错,使用use Rack::Deflater
也会压缩浪费资源但无用的图片。