ruby-on-rails – 如何在Ruby on Rails中启用压缩?
我在这里发了一个类似的问题
Serving Compressed Assets in Heroku with Rack-Zippy 但决定放弃这项服务,因为我不能让它上班. 我在我的网站上运行了PageSpeed Insights,以确定我的网站的速度. 我收到的最重要的建议是启用压缩. Compressing resources with gzip or deflate can reduce the number of bytes sent over the network. Enable compression for the following resources to reduce their transfer size by 191.2KiB (74% reduction). 我按照本网站上的说明进行操作 https://developers.google.com/speed/docs/insights/EnableCompression 并且它说,请参阅您的Web服务器的有关如何启用压缩的文档: 我使用这个网站找出我的网络服务器 http://browserspy.dk/webserver.php 事实证明,我的网络服务器是WEBrick. PageSpeed Insights Page only仅列出以下3个服务器 Apache: Use mod_deflate Nginx: Use ngx_http_gzip_module IIS: Configure HTTP Compression 我搜索了关于WEBrick服务器的gzip压缩文档,但找不到任何东西. 我搜索了如何在Rails中启用压缩,找不到任何东西.这就是为什么我在这里问. 我试过使用Rack Zippy,但放弃了它. 现在我甚至不知道从哪里开始.我的第一步,是找出我应该做什么. 编辑 我遵循艾哈迈德的建议,使用Rack :: Deflator 我确认我已经跑了 rake middleware => use Rack::Deflator 接着 git add . git commit -m '-' git push heroku master 不幸的是,PageSpeed仍然表示需要压缩.我确认,通过进入Developer Tools<网络设置并刷新页面.每个资源的大小和内容几乎相同,意味着文件不被压缩. 我的一个文件有什么问题吗? 感谢您的帮助. 这是我的完整的config / application.rb文件 require File.expand_path('../boot',__FILE__) require 'rails/all' Bundler.require(*Rails.groups) module AppName class Application < Rails::Application config.middleware.use Rack::Deflater config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif) config.exceptions_app = self.routes config.cache_store = :memory_store end end 如果有问题,源头可能在那边,对吧? 我需要安装放气宝石吗? 解决方法
启用压缩
将其添加到config / application.rb中: module YourApp class Application < Rails::Application config.middleware.use Rack::Deflater end end 资料来源:http://robots.thoughtbot.com/content-compression-with-rack-deflater (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |