简体   繁体   English

使用Rack-Zippy在Heroku中提供压缩资产

[英]Serving Compressed Assets in Heroku with Rack-Zippy

I followed this tutorial on how to compress assets in Heroku. 我按照本教程介绍了如何在Heroku中压缩资产。

http://www.cheynewallace.com/serving-compressed-assets-with-heroku-rack-zippy/ http://www.cheynewallace.com/serving-compressed-assets-with-heroku-rack-zippy/

Here is my Application.rb file 这是我的Application.rb文件

require File.expand_path('../boot', __FILE__)

require 'rails/all'

Bundler.require(*Rails.groups)

module Blog
  class Application < Rails::Application

    config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
    config.exceptions_app = self.routes

    config.cache_store = :memory_store
    Rails.application.config.middleware.swap(ActionDispatch::Static, 
    Rack::Zippy::AssetServer, Rails.public_path)

  end
end

My Gem File 我的宝石档案

gem 'yui-compressor', '~> 0.12.0'
gem 'rack-zippy'

I ran heroku run rake middleware and got eh following output 我运行heroku运行rake中间件并在输出后得到eh

use Rack::Sendfile
use Rack::Zippy:AssetServer

Now when I go to Developer Tools and the Network Tab, I see that the size is nearly identical to the content for every asset. 现在,当我转到“开发人员工具”和“网络”选项卡时,我看到大小几乎与每个资产的内容相同。 Which means the assets were not compressed. 这意味着资产没有被压缩。

The only similar question I could find was this one 我可以找到的唯一类似问题是

rack-zippy and option -d in production env doesn't serve static assets 生产环境中的rack-zippy和option -d不提供静态资产

And the answer didn't work. 而且答案没有用。

Should I use another Compressor, because it looks like Rack Zippy does not work. 我是否应该使用其他Compressor,因为它看起来像Rack Zippy无法正常工作。

I had a similar problem. 我有一个类似的问题。 Things started to work when I set config.assets.compile to false on config/environments/production.rb . 当我在config/environments/production.rb上将config.assets.compile设置为false时,事情开始起作用。

In addition is necessary pre-compile the assets before deploy. 另外,在部署之前必须预先编译资产。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM