【问题标题】:Gzip compression not working for XHR requestsGzip 压缩不适用于 XHR 请求
【发布时间】:2017-12-15 06:34:34
【问题描述】:

应用程序托管在使用 Apache 版本 Apache/2.4.18(Ubuntu) 的 AWS 环境中。我已经使用 .htaccess 启用了压缩,它在我的本地系统环境中运行良好。但不是在 AWS 环境中。

除 Ajax 请求外,所有其他 Web 请求都使用 Gzip 在 AWS 上进行压缩。我是否需要启用其他任何东西。

这是我使用的 .htaccess 代码。

<IfModule mod_gzip.c> mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file .(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* </IfModule>

【问题讨论】:

    标签: amazon-web-services gzip


    【解决方案1】:

    通过在 .htaccess 中使用 mod_filters 解决了这个问题。只需将其粘贴到 .htaccess -

    <IfModule mod_filter.c> AddOutputFilterByType DEFLATE "application/atom+xml" \ "application/javascript" \ "application/json" \ "application/ld+json" \ "application/manifest+json" \ "application/rdf+xml" \ "application/rss+xml" \ "application/schema+json" \ "application/vnd.geo+json" \ "application/vnd.ms-fontobject" \ "application/x-font-ttf" \ "application/x-javascript" \ "application/x-web-app-manifest+json" \ "application/xhtml+xml" \ "application/xml" \ "font/eot" \ "font/opentype" \ "image/bmp" \ "image/svg+xml" \ "image/vnd.microsoft.icon" \ "image/x-icon" \ "text/cache-manifest" \ "text/css" \ "text/html" \ "text/javascript" \ "text/plain" \ "text/vcard" \ "text/vnd.rim.location.xloc" \ "text/vtt" \ "text/x-component" \ "text/x-cross-domain-policy" \ "text/xml" </IfModule>

    【讨论】:

      猜你喜欢
      • 2014-03-23
      • 2016-10-23
      • 1970-01-01
      • 1970-01-01
      • 2019-05-07
      • 1970-01-01
      • 1970-01-01
      • 2021-06-11
      • 2020-08-12
      相关资源
      最近更新 更多