SpringBoot开启Gzip压缩

正文

打开配置文件application.yml

COPY
1
2
3
4
5
6
server:
port: 4000 # 端口(请忽略)
compression:
enabled: true # 开启Gzip
mime-types: application/json,application/xml,text/html,text/xml,text/plain # 数据类型(还有很多数据类型,根据自己的情况修改)
min-response-size: 100 # 开启压缩最小数据字节数默认2048个‘字节’

其中min-response-size: 可能存在一些问题,经过测试,无论设置多少大小都会压缩,如下源码中的解释

COPY
1
2
3
4
5
6
7
8
9
10
11
12
/**
* Return the minimum "Content-Length" value that is required for compression to be
* performed.
* @return the minimum content size in bytes that is required for compression
*/
public DataSize getMinResponseSize() {
return this.minResponseSize;
}

public void setMinResponseSize(DataSize minSize) {
this.minResponseSize = minSize;
}

开启Gzip前

NoGzip

开启Gzip后

YesGzip

Authorship: Lete乐特
Article Link: https://blog.imlete.cn/article/SpringBoot-Gzip.html
Copyright: All posts on this blog are licensed under the CC BY-NC-SA 4.0 license unless otherwise stated. Please cite Lete乐特 's Blog !