Performance: Why CORS matters for APIs
MEDIUM IMPACT
CORS affects how browsers allow or block API requests from different origins, impacting user experience and page functionality.
const cors = require('cors'); app.use(cors({ origin: 'https://example.com' }));
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
next();
});| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Allow all origins with '*' | N/A | N/A | N/A | [X] Bad |
| Restrict origins with specific domain | N/A | N/A | N/A | [OK] Good |