backend-compression
Skill1 starsChanged 10 months agoMITView on GitHub
Add response compression (gzip/deflate) to the backend for improved performance. Use when asked to "add compression", "enable gzip", or "optimize response size".
- Installs packages
In this repository14 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skill-creatorSkill
- backend-ai-agentSkill
- backend-ai-toolsSkill
- backend-auth-clerkSkill
- backend-metricsSkill
- backend-model-creationSkill
- backend-route-creationSkill
- backend-scaffoldingSkill
- backend-websocketSkill
- frontend-auth-clerkSkill
- frontend-hooks-creationSkill
- frontend-scaffoldingSkill
- new-project-scaffoldingSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 51
Only compress text-based content types:
- Distinctive: line 92
Add compression early in the middleware chain, but after logging:
- Distinctive: line 113
Verify compression is working:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Backend Response Compression
This skill adds response compression to a Koa backend using koa-compress.
Overview
Response compression reduces payload size for text-based content (JSON, HTML, JS, CSS), improving network performance especially for mobile clients.
Installation
npm install koa-compressImplementation
Add to apps/backend/src/main.ts:
import compress from 'koa-compress';
import { constants as zlibConstants } from 'zlib';
// Add compression middleware (before routes)
app.use(
compress({
filter(content_type) {
// Compress JSON, text, and other compressible types
return /text|json|javascript|xml|svg/i.test(content_type);
},
threshold: 1024, // Only compress responses larger than 1KB
gzip: {
flush: zlibConstants.Z_SYNC_FLUSH,
},
deflate: {
flush: zlibConstants.Z_SYNC_FLUSH,
},
br: false, // Disable brotli (CPU intensive, gzip is sufficient)
})
);Configuration Options
Filter
Only compress text-based content types:
filter(content_type) {
return /text|json|javascript|xml|svg/i.test(content_type);
}Why? Binary content (images, videos, PDFs) is already compressed. Attempting to compress them wastes CPU and can actually increase size.
Threshold
threshold: 1024, // 1KB minimumWhy? Small responses have minimal benefit from compression, but still incur CPU cost. 1KB is a good balance.
Brotli
br: false,Why? Brotli provides better compression but is significantly more CPU intensive. For most APIs, gzip provides sufficient compression with lower server load. Enable brotli only if:
- You have CPU headroom
- Your responses are large and benefit from higher compression ratios
- Your clients primarily support brotli
Flush Mode
gzip: {
flush: zlibConstants.Z_SYNC_FLUSH,
},Why? Z_SYNC_FLUSH ensures data is flushed immediately, important for streaming responses and keeping memory usage predictable.
Middleware Order
Add compression early in the middleware chain, but after logging:
// 1. Error handling
app.use(errorHandler);
// 2. Logging
app.use(requestLogger);
// 3. Compression (before routes)
app.use(compress({ ... }));
// 4. Body parsing
app.use(bodyParser());
// 5. Routes
app.use(mount('/api/resources', resourceRoutes.routes()));Testing Compression
Verify compression is working:
# Request with gzip support
curl -H "Accept-Encoding: gzip" -I http://localhost:3000/api/resources
# Should see: Content-Encoding: gzipChecklist
- Install
koa-compress:npm install koa-compress - Add middleware to
main.tsbefore routes - Verify with curl that
Content-Encoding: gzipheader is present
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

