简体   繁体   中英

How to serve gzip assets with Rails 5 by default

The Rails documentation tells me this:

By default, gzipped version of compiled assets will be generated, along with the non-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 . But as far as I can tell, it doesn't tell me how to serve the gzip version instead of the regular version.

I feel like I must have to change something in my script tag, no? To indicate that I want to request gzip files. At the moment I just have this line in my html head: <%= 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.
But actually Rails can't do more than generate those files as serve those files is app server responsiblity. How to configure it, it depends if you're using Apache or Nginx . I guess Heroku do this automagically? but maybe I'm wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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