Performance: Axios interceptors
MEDIUM IMPACT
Axios interceptors affect the network request lifecycle and can impact interaction responsiveness and perceived loading times.
axios.interceptors.request.use(config => {
// minimal synchronous logic
config.headers['X-Custom-Header'] = 'value';
return config;
});
axios.interceptors.response.use(async response => {
// async processing without blocking UI
await someAsyncFunction(response.data);
return response;
});axios.interceptors.request.use(config => {
// heavy synchronous logic
for (let i = 0; i < 1000000; i++) { /* slow loop */ }
return config;
});
axios.interceptors.response.use(response => {
// blocking UI with synchronous processing
const start = Date.now();
while(Date.now() - start < 50) {}
return response;
});| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy synchronous logic in interceptors | 0 | 0 | Blocks main thread causing delayed paint | [X] Bad |
| Light synchronous + async logic in interceptors | 0 | 0 | Non-blocking, smooth paint and interaction | [OK] Good |