Skip to content

Light version: pages open quickly, without the 3D graphics. You are seeing the light version because the 3D graphics would be slow on this device. The content is the same.

Turn on 3D

Preparing the graphics. This can take a moment on the first visit.

Henry Lõiv

Web design & development

Quick Answer

Does a VITE_ environment variable hide an API key?

Development 2 min read

No. A VITE_ value used by browser code is not a secret. Vite replaces these values during the build, and they can become part of the JavaScript sent to visitors. An .env file is a configuration mechanism, not encryption for client-side code. 1

Distinguish public identifiers from secrets

Some services intentionally issue publishable keys. That is different from a server secret allowing paid requests or access to restricted data. Judge the key by its permissions and provider guidance, not its variable name.

When a request requires a secret, perform it on a backend or suitable serverless function. The browser can ask your controlled application API for the result. That endpoint still needs appropriate authorization, input checks and abuse controls.

If a secret was already shipped

Treat it as exposed: revoke or rotate it with the provider and inspect usage. Removing the value from the next build does not erase earlier copies. 2

Do not paste your real credential into public “key-checking” websites. Use a fictional marker when inspecting a local build.

Minification, TypeScript types and .gitignore cannot protect a value the application deliberately delivers to a visitor’s browser. The relevant question is where the value runs, not whether the source file happened to be named .env.

Related reading

Frontend development

Sources

  1. Vite: environment variables and exposed client values
  2. OWASP: secrets management

Fact checked:

Let’s talk about your project

Tell me about your project

Tell me what you’d like to build or improve. You don’t need a finished brief — we’ll work out the scope and next steps together.

01 How can I help?
02 How many pages do you need?
03 Which extras do you need? Choose all that apply
04 When does it need to be ready?
05 Project details
06 Your contact details

Enquiry received

Thank you!

Your enquiry has been received. I usually reply by email within 2 working days.