Spring Boot 开启压缩功能

Spring Boot 版本:2.2.2.RELEASE


配置

修改 application.yml 配置文件,添加:

#-- 服务器
server:
  compression:
    enabled: true
    mime-types:
    - text/html
    - text/xml
    - text/plain
    - text/css
    - text/javascript
    - application/javascript
    - application/json
    - application/xml

以上第 5 ~ 13 行,如果没有特殊要求,可以省略。

因为在 org.springframework.boot.web.server.Compression 类中,mimeTypes 已经有默认值(第 7、8 行):

package org.springframework.boot.web.server;

public class Compression {

	private boolean enabled = false;

	private String[] mimeTypes = new String[] { "text/html", "text/xml", "text/plain", "text/css", "text/javascript",
			"application/javascript", "application/json", "application/xml" };
}

测试

未开启压缩功能之前,接收一个 JSON 传输的大小:
在这里插入图片描述

开启压缩功能之后,接收一个 JSON 传输的大小:
在这里插入图片描述

发布了36 篇原创文章 · 获赞 0 · 访问量 1874

猜你喜欢

转载自blog.csdn.net/qq_29761395/article/details/103723956