简体   繁体   English

如何使用Rails 5默认提供gzip资产

[英]How to serve gzip assets with Rails 5 by default

The Rails documentation tells me this: Rails文档告诉我这个:

By default, gzipped version of compiled assets will be generated, along with the non-gzipped version of assets. 默认情况下,将生成编译资产的gzip压缩版本以及非gzip压缩版本的资产。

http://guides.rubyonrails.org/asset_pipeline.html#serving-gzipped-version-of-assets http://guides.rubyonrails.org/asset_pipeline.html#serving-gzipped-version-of-assets

It's in a section titled 5.3 Serving GZipped version of assets . 它位于标题为5.3 Serving GZipped版本资产的部分 But as far as I can tell, it doesn't tell me how to serve the gzip version instead of the regular version. 但据我所知,它并没有告诉我如何提供gzip版本而不是普通版本。

I feel like I must have to change something in my script tag, no? 我觉得我必须要更改脚本标签中的内容,不是吗? To indicate that I want to request gzip files. 表示我想要请求gzip文件。 At the moment I just have this line in my html head: <%= javascript_include_tag 'application' %> . 目前我只是在我的html头中有这一行: <%= javascript_include_tag 'application' %>

I'm sure the solution is simple, but it has eluded me. 我确信解决方案很简单,但它让我望而却步。

我想你想要heroku-deflater gem,它增加了中间件以服务于gzip资产?

Yes, maybe that Serving GZipped version of assets title is wrong as it actually indicates how to enable/disable the gzip assets generation. 是的,也许Serving GZipped版本的资产标题是错误的,因为它实际上表明如何启用/禁用gzip资产生成。
But actually Rails can't do more than generate those files as serve those files is app server responsiblity. 但实际上Rails不能生成那些文件,因为服务这些文件是app server的责任。 How to configure it, it depends if you're using Apache or Nginx . 如何配置它取决于您使用的是Apache还是Nginx I guess Heroku do this automagically? 我猜Heroku是否会自动执行此操作? but maybe I'm wrong. 但也许我错了。

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

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