Performance: Environment variables ($env)
This affects page load speed and bundle size by controlling which environment variables are included in the client bundle.
import { PUBLIC_API_URL } from '$env/static/public'; console.log(PUBLIC_API_URL);
import { env } from '$env/dynamic/public'; console.log(env);
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Dynamic import of all env vars | Minimal | 0 | Low but delayed due to JS parsing | [X] Bad |
| Static import of specific env vars | Minimal | 0 | Low and fast | [OK] Good |
import { PUBLIC_APP_NAME } from '$env/static/public';
<h1>Welcome to {PUBLIC_APP_NAME}!</h1>
import { SECRET_KEY } from '$env/static/private';
console.log(SECRET_KEY);
But you get an error during build. What is the likely cause?PUBLIC_GREETING. You also want to update this message without rebuilding the app. Which approach should you use?Pass the test and this pattern moves unknown