⚡ HTTP/2 = Performance
HTTP/1.1 is slow. HTTP/2 is fast. Multiplexing, server push, header compression.
📝 HTTP/2 Features
# 1. Multiplexing - Single connection - Multiple requests - No head-of-line blocking - Faster loading # 2. Server Push - Push resources early - Reduce round trips - Faster page load # 3. Header Compression - Smaller headers - Less bandwidth - Faster parsing # 4. Binary Protocol - More efficient - Faster parsing - Lower overhead # 5. Stream Prioritization - Priority for important resources - Better user experience
🎯 Implementing HTTP/2
# Enable HTTP/2 in Nginx
server {
listen 443 ssl http2;
listen 80;
server_name example.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
}
# Enable HTTP/2 in Apache
Protocols h2 http/1.1
# Node.js HTTP/2
const http2 = require('http2');
const fs = require('fs');
const server = http2.createSecureServer({
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
});
server.on('stream', (stream, headers) => {
stream.respond({
'content-type': 'text/html',
':status': 200
});
stream.end('Hello HTTP/2
');
});
server.listen(443);
# Server Push (Nginx)
location / {
http2_push /style.css;
http2_push /script.js;
}
# Enable in .NET Core
app.UseHttpsRedirection();
app.UseHttp2();
# Check HTTP/2 support
curl --http2 -I https://example.com
💡 HTTP/2 Tips
- Use HTTPS (required for HTTP/2)
- Reduce number of requests
- Use server push for critical resources
- Monitor performance improvements
- Use HTTP/2 with CDN
“HTTP/2 is faster. Multiplexing, server push, compression. Essential for performance.”
