Performance: Why routing matters
Routing affects server response time and how quickly the browser receives content, impacting page load speed and user interaction.
app.get('/user', async (req, res) => { const userData = await fetchUserData(); res.send(userData); });
app.use((req, res, next) => {
// heavy synchronous processing
for (let i = 0; i < 1e8; i++) {}
next();
});
app.get('/user', (req, res) => {
res.send('User page');
});| Pattern | Server Processing | Response Delay | Network Impact | Verdict |
|---|---|---|---|---|
| Blocking synchronous middleware | High CPU blocking | High delay | No impact | [X] Bad |
| Async route handlers | Non-blocking | Low delay | No impact | [OK] Good |
/home in Express?/about given this Express code?app.get('/about', (req, res) => {
res.send('About us page');
});
app.get('/contact', (req, res) => {
res.send('Contact page');
});app.get('/hello', (req, res) => {
res.send('Hello World');
});
app.get('/hello') {
res.send('Hi again');
}'Hello, user!' when visiting /user/:name, where :name is any username. Which code correctly implements this dynamic routing?Pass the test and this pattern moves unknown