是否阿帕奇2 gzip的JSON输出默认? [英] Does Apache 2 gzip json output by default?

查看:202
本文介绍了是否阿帕奇2 gzip的JSON输出默认?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个PHP code的JSON输出。请问apache的默认gzip压缩吗?或者说,我怎么能检查,以确保?

 标题(内容类型:应用程序/ JSON');
标题(缓存控制:最大年龄= 0,无缓存,无店铺,检查后= 0,pre-检查= 0');
头('过期:星期一,1997 GMT 5点00分00秒7月26日');
回声json_en code($响应);


解决方案

这是什么样的伎俩对我来说:

(假设你有机会获得Apache的配置)

  AddOutputFilterByType DEFLATE应用/ JSON

我直接在 /etc/apache2/mods-available/deflate.conf 加入这一行(所以它会为在Web服务器上的每个JSON文件工作)也许别的地方更适合于您的使用情况(例如,如果您只想启用一个Web应用程序,而不是默认的JSON COM pression)。

编辑:在谷歌铬合金的开发工具,你可以很容易地检查你的内容供应COM pressed或uncom pressed:的 http://webmasters.stackexchange.com/a/4613

I'm using this PHP code for json output. Does apache gzip it by default? Or, how can I check to make sure?

header('Content-type: application/json');
header('Cache-Control: max-age=0,no-cache,no-store,post-check=0,pre-check=0');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
echo json_encode($response);

解决方案

This is what did the trick for me:

(assuming you have access to apache configuration)

AddOutputFilterByType DEFLATE application/json

I added this line directly in /etc/apache2/mods-available/deflate.conf (so it will work for every json file on the webserver) maybe someplace else is better suited in your use case (e.g. if you only want to enable json compression for a single web application and not by default).

edit: In google chromes developer tools you can easily check if your content is served compressed or uncompressed: http://webmasters.stackexchange.com/a/4613

这篇关于是否阿帕奇2 gzip的JSON输出默认?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆