Performance: res.download for file downloads
MEDIUM IMPACT
This affects how quickly a file starts downloading and how server resources are used during the download process.
app.get('/file', (req, res) => { res.download('/path/to/file.pdf', 'file.pdf', err => { if (err) res.status(500).send('Error downloading file'); }); });
app.get('/file', (req, res) => { const file = fs.readFileSync('/path/to/file.pdf'); res.setHeader('Content-Disposition', 'attachment; filename="file.pdf"'); res.send(file); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| res.send with fs.readFileSync | 0 (server-side only) | 0 | 0 | [X] Bad |
| res.download streaming file | 0 (server-side only) | 0 | 0 | [OK] Good |