2015-03-28 16:54:53 +00:00
|
|
|
|
### 64.17.1. 启用Tomcat的HTTP响应压缩
|
2015-03-28 16:52:36 +00:00
|
|
|
|
|
2015-03-28 16:54:53 +00:00
|
|
|
|
Tomcat对HTTP响应压缩提供内建支持。默认是禁用的,但可以通过application.properties轻松的启用:
|
|
|
|
|
```java
|
|
|
|
|
server.tomcat.compression: on
|
|
|
|
|
```
|
|
|
|
|
当设置为`on`时,Tomcat将压缩响应的长度至少为2048字节。你可以配置一个整型值来设置该限制而不只是`on`,比如:
|
|
|
|
|
```java
|
|
|
|
|
server.tomcat.compression: 4096
|
|
|
|
|
```
|
|
|
|
|
默认情况下,Tomcat只压缩某些MIME类型的响应(text/html,text/xml和text/plain)。你可以使用`server.tomcat.compressableMimeTypes`属性进行自定义,比如:
|
|
|
|
|
```java
|
|
|
|
|
server.tomcat.compressableMimeTypes=application/json,application/xml
|
|
|
|
|
```
|