Performance: Serving static files
HIGH IMPACT
This affects how quickly static assets like images, CSS, and JavaScript files load, impacting page load speed and user experience.
import express from 'express'; const app = express(); app.use(express.static('public')); app.listen(3000);
const http = require('http'); const fs = require('fs'); http.createServer((req, res) => { if (req.url === '/style.css') { fs.readFile('./style.css', (err, data) => { if (err) { res.writeHead(404); res.end('Not found'); return; } res.writeHead(200, {'Content-Type': 'text/css'}); res.end(data); }); } else { res.writeHead(404); res.end('Not found'); } }).listen(3000);
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Reading files on every request | N/A | N/A | Delays paint due to slow resource load | [X] Bad |
| Using express.static middleware | N/A | N/A | Fast paint due to quick resource delivery | [OK] Good |