How to hide linked JavaScript file in HTML

Viewed 59

I am a beginner and I am learning. Now I am working with API. In some cases, I have to use my private API keys in the JavaScript file. If I publish the webpage somewhere anyone can see the private API keys by clicking on view page source on the browser.

I always write JavaScript codes in a separate file and link them with the HTML file by the script tag.

Is there any way to hide the JavaScript file or is there any way to prevent the leaking of private API keys?

1 Answers

All the code you put in JavaScript is available to public. In the common case you need to create kind of middle-server, which proxies your request to api-server with your private credentials.

Related