开启Gzip压缩功能后,服务对资源进行Gzip压缩后返回,缩小传输文件大小,提升文件传输效率,减少带宽消耗。

Spring Boot配置方法

1
2
3
4
#是否开启压缩,默认为false
server.compression.enabled=true
#指定要压缩的MIME type
server.compression.mime-types=text/*,image/*,application/javascript,application/xml,application/x-font-ttf,application/font-woff

Tomcat配置方法

1
2
3
4
5
6
7
8
9
10
server.xml
<Connector port="8080"
protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/*,image/*,application/javascript,application/xml,application/x-font-ttf,application/font-woff"
/>