A preface

This article is about the technical points of spirngboot on response compression; Mainly to save the cost of network transmission;

Public account: Knowledge seeker

Inheriting the spirit of open Source, Spreading technology knowledge;

Introduction to GZIP compression

In restful requests, we typically submit text in HTTP JSON format; In order to reduce the cost of network transmission, compressed request technology is usually enabled. The HTPP request header contains content-encoding: gzip.

SpringBoot Enables Gzip compression

If it is a Springboot project, gZIP compression technology is not enabled by default, and we need to manually configure and enable it. According to different response formats, the type of enabled is also different. Knowledge seeker gives common media type compression below; If application.properties is configured as follows:

server.compression.enabled=true
server.compression.mime-types=application/javascript,text/css,application/json,application/xml,text/html,text/xml,text/plain
Copy the code

Add the following configuration to application.yml:

server:
  compression:
    enabled: true
    min-response-size: 1024
    mime-types: application/javascript,application/json,application/xml,text/html,text/xml,text/plain,text/css,image/*
Copy the code

The difference between compressed and uncompressed is that the speed of response will vary greatly, and the volume of text carried will vary; Enabling compression technology can reduce bandwidth. It is recommended that you enable GZIP compression to speed up requests and responses.

Tomcat Enable Gzip compression

To use gzip in Tomcat, add the following attributes to the Connector label in server. XML

compression=”on” compressionMinSize=”2048″ compressableMimeType=”text/html,text/css,text/javascript”

Five test

Gzip compression is enabled on the front end. By default, Google Chrome enables ZIP compression

Enable gzip compression on the backend

The difference between 1.2MB and 670KB is still significant; Response time is also very different, although no screenshots, can also guess;

This set of tutorials

  • Springboot introduction (1)
  • Springboot Custom banner(2)
  • Springboot configuration file parsing (3)
  • Springboot integration mybatis (4)
  • JdbcTemplate springboot integration (5)
  • Spingboot Unit Test (6)
  • Springboot integration thymeleaf (7)
  • Springboot Multi-file upload (8)
  • Springboot file download (9)
  • Springboot Custom exception Class (10)
  • Springboot Multi-environment Configuration (11)
  • Springboot Automatic configuration principle (12)
  • Springboot integrated with restTemplate interface call (13)
  • Springboot Integrated Task Scheduling (14)
  • Springboot Cross-domain CORS Processing (15)
  • Springboot enables GIZP compression (16)
  • Springboot integration logback (17)
  • Springboot integration Swagger (18)
  • Springboot Integrated Actuator Monitoring (19)
  • Springboot integration mybatis + oracle + druid (20)
  • Springboot integration springsession (21)
  • JWT springboot integration (22)
  • Springboot integration with admin background Monitoring (23)
  • Springboot Integration redis Basics (24)
  • Redis Cache with SpringBoot
  • Springboot uses AOP log interception (26)
  • Springboot integration Validation (27)
  • Springboot integration mybatisPlus (28)
  • Springboot integration shiro (29)
  • Springboot implementation of interface parity check (30)
  • Springboot – integrated web sockets (31)
  • RestTemplate (32)
  • SpringBoot uses @async asynchronous calls with thread pools (33)
  • To be continued