perf: configure API response compression with Gzip/Deflate in Next.js… - #554
Merged
ayshadogo merged 2 commits intoAug 27, 2026
Merged
Conversation
|
@Unclebaffa Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
… and Axios clients
Unclebaffa
force-pushed
the
perf/api-response-compression
branch
from
August 26, 2026 19:52
2c5f5cc to
1e16b3c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description: [Performance] API Response Compression
📌 Overview
This pull request addresses uncompressed API network payloads by configuring backend response compression (Gzip / Deflate / Brotli) in Next.js, optimizing HTTP client request headers (
Accept-Encoding: gzip, deflate, br), enabling automated decompression in Node/SSR runtimes, setting appropriateVary: Accept-Encodingcaching headers, and adding verification route handlers and unit tests.🎯 Motivation & Problem Statement
🛠️ Changes Implemented
1. Next.js Server & Header Compression Configuration (
next.config.js)compress: trueexplicitly innextConfigto instruct the Next.js server runtime to gzip/deflate-compress responses exceeding 1KB.async headers()to injectVary: Accept-Encodingonto all/api/:path*routes to ensure CDNs, proxy servers, and browser caches correctly cache separate compressed variants.2. HTTP Client Configuration (
Axios)Configured default headers and decompression settings across all Axios client instances:
app/services/api.ts: AddedAccept: 'application/json','Accept-Encoding': 'gzip, deflate, br', anddecompress: true.utils/apiClient.ts: AddedAccept: 'application/json','Accept-Encoding': 'gzip, deflate, br', anddecompress: true.lib/api/client.ts: AddedAccept: 'application/json','Accept-Encoding': 'gzip, deflate, br', anddecompress: true.3. API Route Handlers
app/api/health/route.ts: Added a health check endpoint returning server status and supported compression encoding formats (gzip,deflate,br) withVary: Accept-Encodingand cache control headers.app/api/compression/route.ts: Added a structured mock endpoint (~10KB payload) designed to verify payload size reduction directly in the browser Network tab.4. Continuous Integration & Unit Tests
.github/workflows/ci.yml: Added GitHub Actions CI pipeline executing all 5 validation checks (type-check,lint,format:check,test,build).lib/api/__tests__/compression.test.ts: Created 7 unit tests covering:next.config.jscompress: trueandVary: Accept-Encodingcustom headers.decompress: trueflag./api/healthand/api/compression).📊 Verification & Test Matrix
All 5 verification gates passed with zero errors:
npm run type-check(tsc --noEmit)npm run lint(next lint)npm run format:check(prettier --check)npm test(vitest run)npm run build(next build)🔍 How to Verify in Network Tab
npm run build && npm start(ornpm run dev)./api/compressionor/api/health.Content-Encoding: gzipVary: Accept-Encoding📁 Files Changed
next.config.js: Servercompress: trueandVary: Accept-Encodingheaders.app/services/api.ts: Axios compression headers &decompress: true.utils/apiClient.ts: Axios compression headers &decompress: true.lib/api/client.ts: Axios compression headers &decompress: true.app/api/health/route.ts: New health check route handler.app/api/compression/route.ts: New compression verification route handler.lib/api/__tests__/compression.test.ts: New test suite for compression settings..github/workflows/ci.yml: GitHub Actions CI pipeline configuration.Closes #529