Performance: Reading files asynchronously with callbacks
MEDIUM IMPACT
This affects how fast the page or server can respond while waiting for file data, impacting input responsiveness and overall user experience.
const fs = require('fs'); fs.readFile('file.txt', 'utf8', (err, data) => { if (err) throw err; console.log(data); });
const fs = require('fs'); const data = fs.readFileSync('file.txt', 'utf8'); console.log(data);
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous file read | N/A | Blocks event loop | N/A | [X] Bad |
| Asynchronous file read with callback | N/A | Non-blocking | N/A | [OK] Good |