Try   HackMD

Add Compress Response Middleware for Services

After sharing Reduce Initial Bundle Size for CMS with my teammates, my team lead finds out the way to add compress response middleware for gzip content encoding. In this method, we don't need to add CompressionWrbpackPlugin to generate .gz file or add compression module in our express server. Just add a configuration for Traefik middleware. Here are simple steps below.

1. Add Middleware

apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: compress-response
spec:
  compress: {}

2. Apply Middleware for K8S Ingress

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: admin-ingress
spec:
  entryPoints:
    - websecure
  routes:
    - match: Host(`SLD.TLD`)
      kind: Rule
      services:
        - name: admin
          port: xxxx
      middlewares:
        - name: max-request-body-size-limit
    - match: Host(`SLD.TLD`) && PathPrefix(`/page`)
      kind: Rule
      services:
        - name: admin-vue
          port: yyyy
      middlewares:
        - name: compress-response

3. Final Result

AS-IS

User pays about 1~4 seconds for the page response.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

TO-BE

User pays about 0~2 seconds for the page response.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Reference

tags: Work K8S