⚡ 30% Faster API Calls
Each fetch opens new TCP connection. Handshake overhead. Connection: keep-alive reuses connections. Faster subsequent requests.
📝 Server Configuration
# Node.js (Express) const server = app.listen(3000); server.keepAliveTimeout = 60000; // 60 seconds server.headersTimeout = 61000; # Nginx keepalive_timeout 65s; keepalive_requests 100; # Apache KeepAlive On MaxKeepAliveRequests 100 KeepAliveTimeout 5 # IIS
🎯 Client Considerations
// Fetch automatically uses keep-alive if server supports it
fetch('/api/data');
// For XMLHttpRequest
const xhr = new XMLHttpRequest();
xhr.open('GET', '/api/data');
xhr.setRequestHeader('Connection', 'keep-alive');
xhr.send();
// Axios uses keep-alive by default
axios.get('/api/data');
// Browser limit: 6 connections per domain
// Use HTTP/2 instead (single connection)
💡 Benefits
- Reduces TCP handshake overhead (3-way handshake)
- Reduces TLS negotiation time (HTTPS)
- Improves latency for sequential requests
- Reduces server CPU usage (fewer connections)
- HTTP/2 makes this less critical (multiplexing)
“First API call: 200ms. Subsequent: 50ms. keep-alive made the difference. Should be default everywhere.”
