HTTP-Compression 在 rails 不适用于 JSON-responses
HTTP-Compression in rails not working for JSON-responses
我有 rails 3.2.1 应用程序和 nginx。
在 nginx 配置中,我设置了 gzip on;
,并且对页面、css、js 文件进行压缩。
但它不适用于 JSON 响应。正如我发现 rails 的解决方案是添加: config.middleware.use Rack::Deflater
到 application.rb.
这很有帮助:响应之前是 45Kb,现在接近 8Kb。
但是,现在我发现压缩仅在 Mac Chrome、Mac Firefox 和 Windows Chrome.
中有效
对于 IE 10、IE 11 和 Windows Firefox - 它不起作用:
- 我在 request-header、
中看到 Accept-Encoding: gzip, deflate
- 我在 response-header、
中没有看到 Content-Encoding: gzip
- 响应大小仍然是 45Kb。
拜托,帮忙。
已通过将压缩配置从 rails 移动到 nginx 配置来修复。
我添加到 <my_site>.conf
:
# Enable Gzip
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_proxied any;
gzip_types
# text/html is always compressed by HttpGzipModule
text/css
text/javascript
text/xml
text/plain
text/x-component
application/javascript
application/json
application/xml
application/rss+xml
font/truetype
font/opentype
application/vnd.ms-fontobject
image/svg+xml;
gzip_static on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
感谢@Alexey Ten 的帮助。
有效,但压缩在 IE 中不可见。
Windows 上的一些安全程序捕获 "gzipped" HTTP-responses,从存档中提取它,检查病毒并从响应的 header 中删除 Content-Encoding: gzip
。 IE 一如既往地出色 :)
我有 rails 3.2.1 应用程序和 nginx。
在 nginx 配置中,我设置了 gzip on;
,并且对页面、css、js 文件进行压缩。
但它不适用于 JSON 响应。正如我发现 rails 的解决方案是添加: config.middleware.use Rack::Deflater
到 application.rb.
这很有帮助:响应之前是 45Kb,现在接近 8Kb。
但是,现在我发现压缩仅在 Mac Chrome、Mac Firefox 和 Windows Chrome.
中有效对于 IE 10、IE 11 和 Windows Firefox - 它不起作用:
- 我在 request-header、 中看到
- 我在 response-header、 中没有看到
- 响应大小仍然是 45Kb。
Accept-Encoding: gzip, deflate
Content-Encoding: gzip
拜托,帮忙。
已通过将压缩配置从 rails 移动到 nginx 配置来修复。
我添加到 <my_site>.conf
:
# Enable Gzip
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_proxied any;
gzip_types
# text/html is always compressed by HttpGzipModule
text/css
text/javascript
text/xml
text/plain
text/x-component
application/javascript
application/json
application/xml
application/rss+xml
font/truetype
font/opentype
application/vnd.ms-fontobject
image/svg+xml;
gzip_static on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
感谢@Alexey Ten 的帮助。
有效,但压缩在 IE 中不可见。
Windows 上的一些安全程序捕获 "gzipped" HTTP-responses,从存档中提取它,检查病毒并从响应的 header 中删除 Content-Encoding: gzip
。 IE 一如既往地出色 :)