在Heroku服务压缩资产与机架Zippy [英] Serving Compressed Assets in Heroku with Rack-Zippy

查看:151
本文介绍了在Heroku服务压缩资产与机架Zippy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照本教程介绍了如何压缩Heroku中的资源。



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



这是我的Application.rb文件

  require File.expand_path ',__FILE__)

需要'rails / all'

Bundler.require(* Rails.groups)

模块博客
类应用, 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

我的Gem文件

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

我运行heroku运行rake中间件得到以下输出

 使用Rack :: Sendfile 
使用Rack :: Zippy:AssetServer

现在,当我访问开发人员工具和网络选项卡时,我发现大小与每个资产的内容几乎相同。



我可以找到的唯一类似的问题是这一个



rack-zippy和生产环境中的选项-d不提供静态资产





使用另一个Compressor,因为它看起来像Rack Zippy不工作。

解决方案

我有一个类似的问题。当我在 config / environments / production.rb 上将 config.assets.compile 设置为false时, / p>

此外,必须在部署前预先编译资产。


I followed this tutorial on how to compress assets in Heroku.

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

Here is my Application.rb file

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

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

And the answer didn't work.

Should I use another Compressor, because it looks like Rack Zippy does not work.

解决方案

I had a similar problem. Things started to work when I set config.assets.compile to false on config/environments/production.rb.

In addition is necessary pre-compile the assets before deploy.

这篇关于在Heroku服务压缩资产与机架Zippy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆