Inspired by the Google Maps API way of fetching JS file I would like to serve my clients a JS file with compiled ENV variable depending on their request parameters. I know that Google's way is for authentication only.
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"
async defer></script>
So if my customer would use this in theirs HTML
<script src="https://myapi.com/api/js?myEnvVariable=VARIABLE_VALUE" async defer></script>
they would get a script that would contain this value built somewhere inside and effectively mimic the use of .env files.
var someValue = VARIABLE_VALUE;
What would be the best option to do that?
window.myEnvVariable=VARIABLE_VALUE on client and do not complicateAny ideas?