Performance: CORS configuration
MEDIUM IMPACT
CORS configuration affects the network request flow and browser security checks, impacting page load speed and interaction responsiveness.
const cors = require('cors'); const corsOptions = { origin: 'https://example.com', methods: ['GET', 'POST'], allowedHeaders: ['Content-Type'], optionsSuccessStatus: 204 }; app.use(cors(corsOptions));
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
});| Pattern | Network Requests | Preflight Requests | Blocking Time | Verdict |
|---|---|---|---|---|
| Wildcard '*' origin | Multiple requests | Many preflights | Blocks rendering and interaction | [X] Bad |
| Specific origin and methods | Fewer requests | Minimal preflights | Non-blocking, faster interaction | [OK] Good |