Compression
The Compression plugin compresses HTTP responses to reduce bandwidth and improve performance.
Basic Usage
Section titled “Basic Usage”import { Shokupan, Compression } from 'shokupan';
const app = new Shokupan();
app.use(Compression());
app.listen();Configuration
Section titled “Configuration”app.use(Compression({ threshold: 1024, // Only compress responses larger than 1KB level: 6 // Compression level (1-9, default: 6)}));Options
Section titled “Options”- threshold: Minimum response size to compress (in bytes, default: 1024)
- level: Compression level from 1 (fastest) to 9 (best compression), default: 6
How It Works
Section titled “How It Works”The plugin automatically:
- Checks if the client supports gzip encoding
- Compresses responses larger than the threshold
- Sets appropriate
Content-Encodingheader - Adjusts
Content-Lengthheader
Best Practices
Section titled “Best Practices”// Use default settings for most casesapp.use(Compression());
// For better performance, increase thresholdapp.use(Compression({ threshold: 2048 // 2KB}));
// For better compression, increase levelapp.use(Compression({ level: 9 // Maximum compression}));Next Steps
Section titled “Next Steps”- CORS - Configure CORS
- Security Headers - Add security headers