【问题标题】:How to add gzip support in Nginx for XHR type?如何在 Nginx 中为 XHR 类型添加 gzip 支持?
【发布时间】:2017-02-20 02:46:38
【问题描述】:

Google PageSpeed Insights 建议我对文件 asyncload.php 使用 gzip 压缩。

查看开发者工具,asyncload.php服务的内容在XHR类型下。

我正在使用 Nginx,这是我当前在 nginx.conf 中支持 gzip 的配置。

gzip on;
gzip_comp_level 9;
gzip_http_version 1.1;
gzip_proxied any;
gzip_min_length 10;
gzip_buffers 16 8k;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/xhtml+xml;

# Disable for IE < 6 because there are some known problems
gzip_disable “MSIE [1-6].(?!.*SV1)”;

# Add a vary header for downstream proxies to avoid sending cached gzipped files to IE6
gzip_vary on;

我的问题是:

  1. 如何在通过 PHP 脚本提供的 XHR 类型上添加 gzip 压缩?

  2. XHR 是否在所有浏览器上都完全支持 gzip 压缩?

【问题讨论】:

    标签: nginx gzip


    【解决方案1】:

    我找到了自己的解决方案。

    仔细查看所服务文件的Headers,响应标头显示为Content-Type:application/json

    我在gzip_types 指令列表中添加了application/json,它解决了问题。

    现在提供的文件是 gzip 压缩的,没有 PageSpeed Insights 警告。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-07
      • 1970-01-01
      • 2016-10-02
      • 1970-01-01
      相关资源
      最近更新 更多