Performance: Setting headers and params
MEDIUM IMPACT
This affects the network request time and how quickly the browser can start processing data from the server.
const headers = new HttpHeaders().set('Authorization', 'Bearer token'); const params = new HttpParams().set('filter', 'all'); this.http.get('/api/data', { headers, params })
this.http.get('/api/data', { headers: new HttpHeaders({ 'Authorization': 'Bearer token', 'X-Custom-Header': 'value', 'Unused-Header': 'remove' }), params: new HttpParams().set('filter', 'all').set('unused', 'remove') })
| Pattern | Request Size | Network Latency | Server Processing | Verdict |
|---|---|---|---|---|
| Unoptimized headers and params | Large (extra headers/params) | Higher due to size | Longer due to extra data | [X] Bad |
| Optimized headers and params | Minimal necessary data | Lower due to smaller size | Faster processing | [OK] Good |