Tomcat压缩

通常,从服务器上请求图片,js文件或者response时,可能请求的内容很大,甚至达到几兆,几十兆的时候。此时,如果网络不好,那么加载速度是很慢的。这时,我们可能会想到要去压缩请求的内容。

我们一提到压缩,可能就会想到http请求压缩。 Accept-Encoding (在http request header中) 和 Content-Encoding (在http response header中)。其实,这里有一种关于Tomcat 压缩请求内容最简单的方法,前后台代码都不需要改动,只用修改一下Tomcat中server.xml里面的配置,服务器返回到浏览器的配置就是压缩过的,同时浏览器会自动解压缩。

具体配置如下:

//   eclipse_workspace/Servers/Tomcat v8.0 Server at localhost-config/server.xml

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" compression="on" compressionMinSize="512" compressableMimeType="application/json,application/xml,image/gif,image/png,text/css,text/html,text/javascript,text/plain,text/xml" />
每天一点点
原文地址:https://www.cnblogs.com/juliazhang/p/10116680.html