Serving Compressed Assets in Heroku with Rack-Zippy

时光怂恿深爱的人放手 提交于 2020-01-05 10:25:52

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/25552802/serving-compressed-assets-in-heroku-with-rack-zippy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!