Apache页面压缩配置问题导致JSON数据传输时间延长

Linux大全评论304 views阅读模式

为加快js文件的下载速度,启用了apache服务器的页面压缩功能。

LoadModule deflate_module modules/mod_deflate.so

......

<IfModule deflate_module>
  DeflateCompressionLevel 9
 AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
 AddOutputFilter DEFLATE css js
</IfModule>

发现ext-all.js等js文件的传输时间明显减少,但是查询服务器返回json数据时间大大延长,原来每次大约为100ms,现在每次大约为5.5秒。

经过追踪,发现原因是apache压缩配置,改为

<IfModule deflate_module>
  DeflateCompressionLevel 9
  #AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
  #AddOutputFilterByType DEFLATE text/html
  #AddOutputFilterByType DEFLATE text/json application/json text/x-json application/x-json
  AddOutputFilterByType DEFLATE text/json
  AddOutputFilter DEFLATE css js
</IfModule>

这样可能牺牲部分文件的传输速度,但json数据的速度明显加快。

推荐阅读:

Struts中异步传送XML和JSON类型的数据 http://www.linuxidc.com/Linux/2013-08/88247.htm

Linux下JSON库的编译及代码测试 http://www.linuxidc.com/Linux/2013-03/81607.htm

企鹅博客
  • 本文由 发表于 2020年9月10日 20:38:33
  • 转载请务必保留本文链接:https://www.qieseo.com/159025.html

发表评论