Performance: Environment variable management
MEDIUM IMPACT
This affects page load speed and runtime performance by controlling how environment variables are injected and accessed in the app bundle and server.
export const loader = () => {
return json({
ENV: {
PUBLIC_API_URL: process.env.PUBLIC_API_URL
}
});
};
// Client-side
const { ENV } = useLoaderData();
console.log(ENV.PUBLIC_API_URL);export const loader = () => {
return json({
ENV: process.env
});
};
// Client-side
const { ENV } = useLoaderData();
console.log(ENV);| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Exposing full process.env to client | N/A | 0 | High due to large bundle parsing | [X] Bad |
| Exposing only needed public env vars | N/A | 0 | Low due to smaller bundle | [OK] Good |