Performance: Environment variables in production
This affects page load speed and security by controlling what data is exposed to the client and how the server handles configuration.
module.exports = { env: { NEXT_PUBLIC_API_KEY: process.env.NEXT_PUBLIC_API_KEY } }; // Keep SECRET_KEY only on server side and access via server code
module.exports = {
env: {
NEXT_PUBLIC_API_KEY: process.env.NEXT_PUBLIC_API_KEY,
NEXT_PUBLIC_SECRET_KEY: process.env.NEXT_PUBLIC_SECRET_KEY
}
};| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Exposing all env vars to client | N/A | 0 | Increased due to larger JS bundle | [X] Bad |
| Exposing only NEXT_PUBLIC_ vars | N/A | 0 | Minimal paint cost, smaller JS bundle | [OK] Good |
console.log(process.env.NEXT_PUBLIC_API_URL);
NEXT_PUBLIC_API_URL=https://api.example.com is set, what will be logged?process.env.NEXT_PUBLIC_API_URL logs as undefined in production. What is the most likely cause?Pass the test and this pattern moves unknown