SpringBoot2开启响应压缩
对响应体进行压缩。可以提高传输效率。但是要耗费一点儿算力对数据进行压缩计算。
SpringBoot的配置
对应的配置类:org.springframework.boot.context.embedded.Compression
server:
compression:
# 开启响应压缩
enabled: true
# 支持的压缩类型
mime-types:
- application/json
- application/xml
- application/javascript
- text/html
- text/xml
- text/plain
- text/css
- text/javascript
# 默认只有响应体大于 2028kb 时才会进行压缩
min-response-size: 2048
# 指定不压缩的user-agent,默认为null
# excluded-user-agents
效果对比
这里拿开发版的
vue.js
来演示
未压缩
压缩后
响应时间和体积减少了。