Skip to main content

Improving Performance with Response Compression

Response compression reduces the size of HTTP response bodies sent from your upstream service, improving page load speeds, reducing bandwidth usage, and enhancing user experience.

When response compression is enabled:

📉 Data transfer sizes are reduced, lowering bandwidth consumption.
⚡ Pages and APIs load faster, especially on slower networks.
🚀 Performance is improved without requiring changes to the upstream service.

🔍 What are the Benefits of Response Compression?​

Every millisecond counts when serving web applications and APIs. Compression is a simple yet effective way to improve performance without modifying backend code.

Response Compression offers the following benefits:

  • Faster Web & API Performance. Users receive responses quicker, reducing page load times.
  • Compress JSON and XML payloads for faster API calls.
  • Lower Bandwidth Usage. Ideal for high-traffic APIs, mobile users, and global applications.
  • Better Client Experience. Reduces latency, especially in areas with slower network connections.
  • Reduces bandwidth usage for users on slow or metered connections.
  • No Backend Changes Needed. Compression is handled at the traffic policy level, requiring zero code modifications.

Response Compression Examples​

When an HTTP request includes an Accept-Encoding header, HTTP responses are automatically compressed, and a Content-Encoding header is added to the response. If the response is already compressed by your upstream service, no additional compression will be applied.

The following examples configure the endpoint to have ngrok compress the response using one of the specified algorithms (e.g., gzip). The response will include the content-encoding: gzip header, and the body will be compressed accordingly.

The traffic policy includes an expression to only run the compression on paths that start with /api/

Check out the compress response traffic policy action page for more details about how it functions and the parameters it accepts.

Loading…