打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Spring Boot 启用Gzip压缩

两点需要注意

1、需要在application.properties里启用压缩,并设置压缩支持的格式(默认支持text/html等,但不支持application/json)

server.compression.enabled=trueserver.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain

2、默认情况下,仅会压缩2048字节以上的内容

#默认就是2048 byteserver.compression.min-response-size=2048

 

以上内容,详见 org.springframework.boot.context.embedded.Compression

以及 org.springframework.boot.autoconfigure.web.ServerProperties

 

另外,这个设置本身是由servlet container提供的,所以,也可以在tomcat等的设置里找到。

对tomcat来说,在server.xml 的HTTP/1.1的connector节点中设置:

<!-- 这里的压缩设置,是默认的 --><Connector port="8888" protocol="HTTP/1.1"                connectionTimeout="21000"                redirectPort="28080"                URIEncoding="UTF-8"               compression="on"                 compressionMinSize="50"               noCompressionUserAgents="gozilla, traviata"                 compressionMinSize = “2048”               compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain" />

 

ps:以上是对于最新的Spring Boot来说的,如果是旧版本的(

 

参考:

Spring 官方指导

使用Tomcat的gzip功能(压缩请求)

tomcat配置gzip压缩compressionMinSize选项无效

Understanding Gzip Compression in Spring Boot ,Angular Java Application

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
76. Spring Boot完美解决(406)Could not find acceptable representation原因及解决方法
spring-boot(三)响应返回json和xml
idea中 maven打包时时报错User setting file does not exist C:\Users\lenevo\.m2\setting.xml,
SpringBoot理解
spring boot(一):入门篇
Spring Boot 整合 MyBatis
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服