Access hidden API key inside js file (git hub pages)

I am building a simple vanilla JS project which uses API keys from third-party sources like (Location IQ and Open weather), but the problem is when I am hiding those keys using git ignore, my main js file is unable to reference those, any way to get around this…

I don’t know how to use environment variables using vanilla js

Answer

No.

.gitignore doesn’t hide anything, it tells Git to ignore it.

If Git ignores it then it won’t check it into the repository. If it isn’t in the repository then Github doesn’t have it. If Github doesn’t have it then it can’t publish it on Github pages.


If you want the browser to make requests directly to APIs that require API keys then you need to give those keys to the browser (and thus to the user who controls the browser).