Can You Securely Store API Keys in Browsers or Frontend Apps?

Storing API keys in a frontend app or browser isn't safe. That's because when your app runs in a browser, everything is exposed.

Your frontend, after being compiled, is really just a bunch of HTML, Javascript, and CSS files. This means that someone can inspect all the global variables you have in memory and track down the key.

To keep your API keys safe, you can use a proxy server. Here's how it works:

Instead of your frontend app talking directly to the API, it talks to a server you control. This server then talks to the API using the API key. This way, the API key stays hidden on your server where it's safe, and only your server communicates with the API.

Get my free, weekly JavaScript tutorials

Want to improve your JavaScript fluency?

Every week, I send a new full-length JavaScript article to thousands of developers. Learn about asynchronous programming, closures, and best practices — as well as general tips for software engineers.

Join today, and level up your JavaScript every Sunday!

Thank you, Taha, for your amazing newsletter. I’m really benefiting from the valuable insights and tips you share.

- Remi Egwuda