0
0
Expressframework~8 mins

res.redirect for redirections in Express - Performance & Optimization

Choose your learning style9 modes available
Performance: res.redirect for redirections
MEDIUM IMPACT
This affects page load speed by causing an additional HTTP request and response cycle before the final content loads.
Redirecting a user to another page after a request
Express
app.get('/old-page', (req, res) => {
  res.status(200).sendFile(__dirname + '/path/to/new-page.html');
});
Serves the final content directly without extra HTTP round trips.
📈 Performance GainEliminates extra request, improving LCP by 100-300ms
Redirecting a user to another page after a request
Express
app.get('/old-page', (req, res) => {
  res.redirect('/new-page');
});
This causes the browser to make a second HTTP request to '/new-page', increasing load time.
📉 Performance CostAdds 1 extra HTTP request, delaying LCP by 100-300ms depending on network
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
res.redirect causing extra HTTP requestN/AN/ABlocks initial paint until redirect completes[X] Bad
Directly serving final content without redirectN/AN/APaints content on first response[OK] Good
Rendering Pipeline
res.redirect sends a 3xx HTTP status causing the browser to pause rendering and request a new URL, delaying content paint.
Network Request
HTML Parsing
Rendering
⚠️ BottleneckNetwork Request due to extra HTTP round trip
Core Web Vital Affected
LCP
This affects page load speed by causing an additional HTTP request and response cycle before the final content loads.
Optimization Tips
1Avoid unnecessary res.redirect calls to reduce extra HTTP requests.
2Each redirect adds network latency and delays Largest Contentful Paint.
3Serve final content directly when possible to improve user experience.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance cost of using res.redirect in Express?
AIt blocks JavaScript execution
BIt causes an extra HTTP request delaying page load
CIt increases DOM nodes on the page
DIt causes CSS recalculation
DevTools: Network
How to check: Open DevTools, go to Network tab, reload page and look for 3xx redirect status codes before final 200 response.
What to look for: Presence of 301/302 status and extra request delaying final content load