Performance: Interceptors for request modification
This affects the time it takes for HTTP requests to be sent and responses to be processed, impacting interaction responsiveness and network efficiency.
intercept(req, next) {
const clonedReq = req.clone({ headers: req.headers.set('Authorization', 'Bearer ' + this.token) });
return next.handle(clonedReq);
}intercept(req, next) {
const clonedReq = req.clone({ headers: req.headers.set('Authorization', 'Bearer ' + this.token) });
return next.handle(clonedReq).pipe(delay(100));
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Interceptor with delay or heavy sync work | 0 | 0 | Blocks UI update indirectly by delaying response | [X] Bad |
| Lightweight interceptor modifying headers only | 0 | 0 | Minimal impact on UI update speed | [OK] Good |
req.clone().intercept(req, next) {
const cloned = req.clone({
setHeaders: { Authorization: 'Bearer token123' }
});
return next.handle(cloned);
}intercept(req, next) {
req.setHeaders({ 'Content-Type': 'application/json' });
return next.handle(req);
}Pass the test and this pattern moves unknown